lib/jekyll/translations.rb in jekyll-translations-0.1.0 vs lib/jekyll/translations.rb in jekyll-translations-1.0.0
- old
+ new
@@ -3,31 +3,32 @@
require 'open-uri'
module Translations
class Generator < Jekyll::Generator
def generate(site)
- translation_source = site.config['translations']['source']
+ translation_sources = site.config['translations']['sources']
- site.data['translations'] = JSON.parse(open(translation_source).read)
+ site.data['translations'] = {}
+ translation_sources.each { |key, value| site.data['translations'][key] = JSON.parse(open(value).read) }
end
end
module TranslateFilter
@translations = []
@localizationContext = nil
@skipTranslationCheck = nil
@debug_translations = false
- def translations
+ def translations(locale)
return @translations if @translations
site = @context.registers[:site]
config = site.config['translations']
@skipTranslationCheck = config['skipTranslationCheck']
@debug_translations = !@skipTranslationCheck and ENV['DEBUG_TRANSLATIONS'].to_i === 1
- translation_data = site.data['translations']
+ translation_data = site.data['translations'][locale]
translations = translation_data['common']
if config['context'] and translation_data[config['context']]
translations = translations.merge(translation_data[config['context']])
end
@@ -44,10 +45,13 @@
def t(text, args = [])
# If we've an array, translate each item and return
return self.translate_array(text) if text.kind_of?(Array)
- @translations = self.translations
+ page = @context.environments.first['page']
+ locale = page['locale'] ? page['locale'] : 'default'
+
+ @translations = self.translations(locale)
# Uncomment the following block to see a list of items missing translations
# if @translations[text].nil?
# puts text.to_json + "\n"
# end