I18n yaml local key synchronization

A similar question, but for java, i18n resource storage

How to keep i18n yaml locals key synchronization? that is, when the key is added to en.yml, how to get them for nb.yml or ru.yml?

if I add the key my_label: "some text in english"next to my_title: "a title", I would like to get this for my other local users, which I specify, since I can not perform all translations, and it must return to English in other languages

eg ru.yml

somegroup:
  my_tile: "a title in english"
  my_label: "some text in english"
othergroup:
  ...

I would like to leave the team and get the whole key and value for input into the Norwegian translation and the corresponding position if it is missing. Then it will git diffdisplay all translations made in this language.

nb.yml

 somegroup:
   my_tile: "En tittel på norsk"
+  my_label: "some text in english"
 othergroup:
   ...

- , - ? , , , , . ?

+5
3
+1

i18n_translation_spawner. - , , script:

Hash deep_merge .

require 'yaml'
class Hash
   def deep_merge(hash)
      target = dup

      hash.keys.each do |key|
         if hash[key].is_a? Hash and self[key].is_a? Hash
            target[key] = target[key].deep_merge(hash[key])
            next
         end
         target[key] = hash[key]
      end
      target
   end

   def fill_all_values value
      each_key do |key|
         if self[key].is_a?(String)
            store(key,value)
         else
            self[key].fill_all_values value
         end
      end
   end
end

:

def merge_yaml_i18n_files(locale_code_A,locale_code_B,untranslated_message)
   hash_A = YAML.load_file("i18n/#{locale_code_A}.yml")
   hash_B = YAML.load_file("i18n/#{locale_code_B}.yml")

   hash_A_ut = Marshal.load(Marshal.dump(hash_A))
   hash_A_ut.fill_all_values(untranslated_message)

   hash_B_ut = Marshal.load(Marshal.dump(hash_B))
   hash_B_ut.fill_all_values(untranslated_message)

   hash_A = hash_B_ut.deep_merge(hash_A)
   hash_B = hash_A_ut.deep_merge(hash_B)

   puts hash_A.to_yaml
   puts hash_B.to_yaml
end

, , :

merge_yaml_i18n_files('en','es','untranslated')

i18n:

es.yaml
test:
   hello: Hola
   only_es: abc

en.yaml
test:
   hello: Hello
   only_en: def

:

es.yaml
test:
   hello: Hola
   only_en: untranslated
   only_es: abc

en.yaml
test:
   hello: Hello
   only_en: def
   only_es: untranslated
+1

i18n-tasks .

a

It scans such calls, as I18n.t('some.key')well as reports on key usage, missing and unused keys. It can also pre-populate missing keys, including from Google Translate, and it can also delete unused keys.

+1
source

All Articles