I’m currently using an i18n plugin called jekyll-multiple-languages-plugin
for my Jekyll website hosted by GitLab Pages. I’m using the modified script klaasnotfound/jekyll-multiple-languages-plugin.rb
for the plugin. However, when I do build the site, it gives me the error: undefined method '+' for nil:NilClass (NoMethodError)
.
Here is the full traceback:
Configuration file: C:/Users/Pradana/umarsaid/_config.yml
Source: C:/Users/Pradana/umarsaid
Destination: C:/Users/Pradana/umarsaid/_site
Incremental build: disabled. Enable with --incremental
Generating...
C:/Users/Pradana/umarsaid/_plugins/jekyll-multiple-languages-plugin/jekyll-multiple-languages-plugin.rb:154:in `block in process': undefined method `+' for nil:NilClass (NoMethodError)
from C:/Users/Pradana/umarsaid/_plugins/jekyll-multiple-languages-plugin/jekyll-multiple-languages-plugin.rb:150:in `each'
from C:/Users/Pradana/umarsaid/_plugins/jekyll-multiple-languages-plugin/jekyll-multiple-languages-plugin.rb:150:in `process'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/jekyll-3.5.0/lib/jekyll/command.rb:26:in `process_site'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/jekyll-3.5.0/lib/jekyll/commands/build.rb:63:in `build'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/jekyll-3.5.0/lib/jekyll/commands/build.rb:34:in `process'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/jekyll-3.5.0/lib/jekyll/commands/build.rb:16:in `block (2 levels) in init_with_program'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/jekyll-3.5.0/exe/jekyll:13:in `<top (required)>'
from C:/Ruby24-x64/bin/jekyll:22:in `load'
from C:/Ruby24-x64/bin/jekyll:22:in `<main>'
Here is class Site
of klaasnotfound/jekyll-multiple-languages-plugin.rb where the issue is being traced back to.
class Site
attr_accessor :parsed_translations # Hash that stores parsed translations read from YAML files.
alias :process_org :process
#======================================
# process
#
# Reads Jekyll and plugin configuration parameters set on _config.yml, sets
# main parameters and processes the website for each language.
#======================================
def process
# Check if plugin settings are set, if not, set a default or quit.
#-------------------------------------------------------------------------
self.parsed_translations ||= {}
self.config['exclude_from_localizations'] ||= []
if ( !self.config['languages'] or
self.config['languages'].empty? or
!self.config['languages'].all?
)
puts 'You must provide at least one language using the "languages" setting on your _config.yml.'
exit
end
# Variables
#-------------------------------------------------------------------------
# Original Jekyll configurations
baseurl_org = self.config[ 'baseurl' ] # Baseurl set on _config.yml
dest_org = self.dest # Destination folder where the website is generated
# Site building only variables
languages = self.config['languages'] # List of languages set on _config.yml
# Site wide plugin configurations
self.config['default_lang'] = languages.first # Default language (first language of array set on _config.yml)
self.config[ 'lang'] = languages.first # Current language being processed
self.config['baseurl_root'] = baseurl_org # Baseurl of website root (without the appended language code)
self.config['translations'] = self.parsed_translations # Hash that stores parsed translations read from YAML files. Exposes this hash to Liquid.
# Build the website for all languages
#-------------------------------------------------------------------------
# Remove .htaccess file from included files, so it wont show up on translations folders.
self.include -= [".htaccess"]
languages.each do |lang|
# Language specific config/variables
@dest = dest_org + "/" + lang
self.config['baseurl'] = baseurl_org + "/" + lang
self.config['lang'] = lang
puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
process_org
end
# Revert to initial Jekyll configurations (necessary for regeneration)
self.config[ 'baseurl' ] = baseurl_org # Baseurl set on _config.yml
@dest = dest_org # Destination folder where the website is generated
puts 'Build complete'
end
if Gem::Version.new(Jekyll::VERSION) < Gem::Version.new("3.0.0")
alias :read_posts_org :read_posts
#======================================
# read_posts
#======================================
def read_posts(dir)
translate_posts = !self.config['exclude_from_localizations'].include?("_posts")
if dir == '' && translate_posts
read_posts("_i18n/#{self.config['lang']}/")
else
read_posts_org(dir)
end
end
end
end