Class: Jekyll::Site
- Inherits:
-
Object
- Object
- Jekyll::Site
- Defined in:
- lib/jekyll/gettext/plugin.rb
Instance Method Summary collapse
- #load_translations ⇒ Object
- #process ⇒ Object
- #process_org ⇒ Object
- #save_missing_translations ⇒ Object
Instance Method Details
#load_translations ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jekyll/gettext/plugin.rb', line 64 def load_translations @all_translations = TranslationLogger.new @missing_translations = TranslationLogger.new repos = [ FastGettext::TranslationRepository.build(self.config['lang'], :type=>:logger, :callback=>@all_translations), FastGettext::TranslationRepository.build(self.config['lang'], :type=>:logger, :callback=>@missing_translations), FastGettext::TranslationRepository.build(self.config['lang'], :path => self.source + "/_i18n", :type => :po) ] FastGettext.add_text_domain(self.config['lang'], :type=>:chain, :chain=>repos) FastGettext.text_domain = self.config['lang'] FastGettext.locale = self.config['lang'] end |
#process ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jekyll/gettext/plugin.rb', line 27 def process if !self.config['baseurl'] self.config['baseurl'] = "" end # variables config['baseurl_root'] = self.config['baseurl'] baseurl_org = self.config['baseurl'] languages = self.config['languages'] dest_org = self.dest # loop self.config['lang'] = languages.first puts puts "Building site for default language: \"#{self.config['lang']}\" to: " + self.dest self.load_translations process_org self.save_missing_translations languages.drop(1).each do |lang| # build site for language lang self.dest = self.dest + "/" + lang self.config['baseurl'] = self.config['baseurl'] + "/" + lang self.config['lang'] = lang puts "Building site for language: \"#{self.config['lang']}\" to: " + self.dest self.load_translations process_org self.save_missing_translations # reset variables for next language self.dest = dest_org self.config['baseurl'] = baseurl_org end puts 'Build complete' end |
#process_org ⇒ Object
26 |
# File 'lib/jekyll/gettext/plugin.rb', line 26 alias :process_org :process |
#save_missing_translations ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/jekyll/gettext/plugin.rb', line 79 def save_missing_translations filename = self.source + "/_i18n/" + self.config['lang'] + '/' + self.config['lang'] + '.po' existing_translations = GetPomo.unique_translations(GetPomo::PoFile.parse(File.read(filename))) # ignores any keys that already exist missing_translations_msgids = @missing_translations.get_translations.reject {|msgid| existing_translations.find {|trans| trans.msgid == msgid}} final_translations = existing_translations missing_translations_msgids.each do |new_msgid| new_trans = GetPomo::Translation.new new_trans.msgid = new_msgid new_trans.msgstr = "" final_translations.push(new_trans) end # uncomment this to remove translations that were not used # not_used = final_translations.reject { |trans| @all_translations.get_translations.find {|msgid| trans.msgid == msgid}} # final_translations = final_translations.reject {|trans1| not_used.find {|trans2| trans1.msgid == trans2.msgid}} final_translations.sort_by!(&:msgid) File.open(filename, 'w'){|f|f.print(GetPomo::PoFile.to_text(final_translations))} end |