Class: I18nPoTools::LocfileUtils
- Inherits:
-
Object
- Object
- I18nPoTools::LocfileUtils
- Defined in:
- lib/i18n_po_tools/utils/locfile.rb
Instance Attribute Summary collapse
-
#dirname ⇒ Object
Returns the value of attribute dirname.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#locales_indexes ⇒ Object
Returns the value of attribute locales_indexes.
-
#po_filename_path ⇒ Object
Returns the value of attribute po_filename_path.
-
#pot_filename_path ⇒ Object
Returns the value of attribute pot_filename_path.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#src_filename_template ⇒ Object
Returns the value of attribute src_filename_template.
-
#template_locales ⇒ Object
Returns the value of attribute template_locales.
-
#translation_files ⇒ Object
Returns the value of attribute translation_files.
-
#translations_dir ⇒ Object
Returns the value of attribute translations_dir.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #convert_from_po_to_src(locale) ⇒ Object
- #convert_from_po_to_src_extra(locale, src_filename, po_filename) ⇒ Object
- #convert_from_src_to_po(locale, base_locale) ⇒ Object
- #convert_from_src_to_po_extra(locale, base_locale, base_filename, src_filename, po_filename) ⇒ Object
- #create_dirs ⇒ Object
- #export_initial_translations ⇒ Object
- #export_messages ⇒ Object
- #generate_pot(locale) ⇒ Object
- #generate_pot_extra(locale, src_filename, pot_filename) ⇒ Object
- #import_translations ⇒ Object
-
#initialize(dirname) ⇒ LocfileUtils
constructor
A new instance of LocfileUtils.
- #merge_pot(locale, base_locale, pot_name) ⇒ Object
- #merge_pot_all ⇒ Object
- #my_command(cmd) ⇒ Object
- #src_filename_template_with_locale(locale) ⇒ Object
Constructor Details
#initialize(dirname) ⇒ LocfileUtils
Returns a new instance of LocfileUtils.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 19 def initialize(dirname) @translations_dir = ENV["I18N_YML_TRANSLATIONS_DIR"] @verbose = true @dirname = File.(dirname) config = YAML.load_file(File.join(dirname, 'Locfile')) @project_name = config["project_name"] @template_locales = config["template_locales"] @locales = config["locales"] @locales_indexes = config["locales_indexes"] @translation_files = config["translation_files"] @src_filename_template = config["src_filename_template"] @pot_filename_path = config["pot_filename_path"].gsub('%{project_name}', project_name) @po_filename_path = config["po_filename_path"].gsub('%{project_name}', project_name) end |
Instance Attribute Details
#dirname ⇒ Object
Returns the value of attribute dirname.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def dirname @dirname end |
#locales ⇒ Object
Returns the value of attribute locales.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def locales @locales end |
#locales_indexes ⇒ Object
Returns the value of attribute locales_indexes.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def locales_indexes @locales_indexes end |
#po_filename_path ⇒ Object
Returns the value of attribute po_filename_path.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def po_filename_path @po_filename_path end |
#pot_filename_path ⇒ Object
Returns the value of attribute pot_filename_path.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def pot_filename_path @pot_filename_path end |
#project_name ⇒ Object
Returns the value of attribute project_name.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def project_name @project_name end |
#src_filename_template ⇒ Object
Returns the value of attribute src_filename_template.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def src_filename_template @src_filename_template end |
#template_locales ⇒ Object
Returns the value of attribute template_locales.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def template_locales @template_locales end |
#translation_files ⇒ Object
Returns the value of attribute translation_files.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def translation_files @translation_files end |
#translations_dir ⇒ Object
Returns the value of attribute translations_dir.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def translations_dir @translations_dir end |
#verbose ⇒ Object
Returns the value of attribute verbose.
7 8 9 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 7 def verbose @verbose end |
Instance Method Details
#convert_from_po_to_src(locale) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 84 def convert_from_po_to_src(locale) src_path = File.join(dirname, src_filename_template_with_locale(locale)) po_path = File.join(translations_dir, po_filename_path.gsub('%{locale}',locale)) translation_files.each_pair do |src_name, pot_name| src_filename = src_path.gsub('%{src_filename}',src_name) po_filename = File.join(po_path, pot_name+".po") cmds = [] cmds << "i18n-po "\ "--output #{src_filename} "\ "--input #{po_filename} "\ "#{convert_from_po_to_src_extra(locale, src_filename, po_filename)}" my_command( cmds.join(';') ) end end |
#convert_from_po_to_src_extra(locale, src_filename, po_filename) ⇒ Object
129 130 131 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 129 def convert_from_po_to_src_extra(locale, src_filename, po_filename) '' end |
#convert_from_src_to_po(locale, base_locale) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 101 def convert_from_src_to_po(locale, base_locale) base_path = File.join(dirname, src_filename_template_with_locale(base_locale)) src_path = File.join(dirname, src_filename_template_with_locale(locale)) po_path = File.join(translations_dir, po_filename_path.gsub('%{locale}',locale)) translation_files.each_pair do |src_name, pot_name| base_filename = base_path.gsub('%{src_filename}', src_name) src_filename = src_path.gsub('%{src_filename}', src_name) po_filename = File.join(po_path, pot_name+".po") cmds = [] cmds << "i18n-po "\ "--output #{po_filename} "\ "--input #{src_filename} "\ "--language #{locale} "\ "--base #{base_filename} "\ "#{convert_from_src_to_po_extra(locale, base_locale, base_filename, src_filename, po_filename)}" my_command( cmds.join(';') ) end end |
#convert_from_src_to_po_extra(locale, base_locale, base_filename, src_filename, po_filename) ⇒ Object
132 133 134 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 132 def convert_from_src_to_po_extra(locale, base_locale, base_filename, src_filename, po_filename) '' end |
#create_dirs ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 42 def create_dirs() template_locales.each do |locale| name = File.join(translations_dir, pot_filename_path.gsub('%{locale}',locale)) my_command("mkdir -p #{name}") end locales.each do |(locale, base_locale)| name = File.join(translations_dir, po_filename_path.gsub('%{locale}',locale)) my_command("mkdir -p #{name}") end end |
#export_initial_translations ⇒ Object
159 160 161 162 163 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 159 def export_initial_translations() locales.each do |(locale, base_locale)| convert_from_src_to_po(locale, base_locale) end end |
#export_messages ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 136 def () create_dirs() template_locales.each do |locale| generate_pot(locale) end #merge new strigns to po files puts puts puts "WARNING:" puts "Ensure that currently translators do not update your project translations." puts puts "Press [Enter] key to start export new strings from POT to PO-files..." gets merge_pot_all() end |
#generate_pot(locale) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 53 def generate_pot(locale) src_path = File.join(dirname, src_filename_template_with_locale(locale)) pot_path = File.join(translations_dir, pot_filename_path.gsub('%{locale}',locale)) translation_files.each_pair do |src_name, pot_name| src_filename = src_path.gsub('%{src_filename}',src_name) pot_filename = File.join(pot_path, pot_name+".pot") cmds = [] cmds << "i18n-po "\ "--input #{src_filename} "\ "--output #{pot_filename} "\ "#{generate_pot_extra(locale, src_filename, pot_filename)}" my_command( cmds.join(';') ) end end |
#generate_pot_extra(locale, src_filename, pot_filename) ⇒ Object
126 127 128 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 126 def generate_pot_extra(locale, src_filename, pot_filename) '' end |
#import_translations ⇒ Object
153 154 155 156 157 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 153 def import_translations() locales.each do |(locale, base_locale)| convert_from_po_to_src(locale) end end |
#merge_pot(locale, base_locale, pot_name) ⇒ Object
70 71 72 73 74 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 70 def merge_pot(locale, base_locale, pot_name) pot_filename = File.join(translations_dir, pot_filename_path.gsub('%{locale}',base_locale),pot_name+".pot") po_filename = File.join(translations_dir, po_filename_path.gsub('%{locale}',locale),pot_name+".po") my_command("msgmerge -U #{po_filename} #{pot_filename}") end |
#merge_pot_all ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 76 def merge_pot_all() locales.each do |(locale, base_locale)| translation_files.each_pair do |src_name, pot_name| merge_pot(locale, base_locale, pot_name) end end end |
#my_command(cmd) ⇒ Object
37 38 39 40 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 37 def my_command(cmd) puts cmd if verbose system(cmd) end |
#src_filename_template_with_locale(locale) ⇒ Object
122 123 124 |
# File 'lib/i18n_po_tools/utils/locfile.rb', line 122 def src_filename_template_with_locale(locale) src_filename_template.gsub('%{locale}',locale) end |