Plots2: Combine all the YAML files present in config/locales in a single file

Created on 23 Jan 2019  路  6Comments  路  Source: publiclab/plots2

At https://github.com/publiclab/plots2/tree/master/config/locales we have all the YAML files in the directories. We want to combine all the files present in those directories with one file for each language. Let's start with English.

Either we can do this task manually or can use some help from existing resources. I have found https://gist.github.com/branch14/1010381 to be useful and have tested it too. Yes, it works.

@jywarren I think we can use above code first to combine and then run https://gist.github.com/branch14/5746d4f117f00490fea5 to count for conflicts. As a precaution, I will look at the combined file closely too for ensuring integrity. Sounds good?

Translation System enhancement

All 6 comments

Can I collaborate with you on working on this?

Hi @akshaygupta533, you can help for sure, I will try to divide the tasks from this one soon. Thanks!

Hi @jywarren @ebarry @steviepubliclab,

Here's the progress at Transifex
overview_translations

As you can see the number of strings reviewed are very less. I have exported the report - https://docs.google.com/spreadsheets/d/1SznxOoZXHnh6gxMyd2lAshSYXSHfHg46JoblBzr__qA/edit?usp=sharing
and you'll find that total number of reviewed strings are 5 (https://docs.google.com/spreadsheets/d/1SznxOoZXHnh6gxMyd2lAshSYXSHfHg46JoblBzr__qA/edit#gid=242146977&range=Q73).

Earlier, I was thinking of exporting all the reviewed strings only but after going through records in detail - I am working to combine Translated strings, of all languages, as just 5 strings are reviewed so I will review those myself after combining. I hope you all agree on this one.

Translated strings: Strings which are translated by someone but not reviewed by any moderator/expert so trust level is less

Reviewed strings: Strings which are translated by someone and reviewed by a moderator/admin/expert so we can trust that translation and use it in our website

Started the process of combining all en.yml files

  1. Used this function below to flatten_hash
  def flatten_hash(hash)

    hash.each_with_object({}) do |(k, v), h|

     if v.is_a? Hash
        flatten_hash(v).map do |h_k, h_v|
          h["#{k}.#{h_k}".to_sym] = h_v
        end
        else
        h[k] = v
     end
  end
  end

Commands run during byebug -->

 p = I18n.backend.translations[:en]
 flatten_hash(p)

Output:
(byebug) Node.first.flatten_hash(p).count
CACHE Node Load (0.0ms) SELECT "node".* FROM "node" ORDER BY "node"."nid" ASC LIMIT ? [["LIMIT", 1]]
875

So, we have 875 strings before combination.

And, our script worked ...:tada: :tada: :tada: :tada: :smile:

After running script and some cleaning(the script also included the german and chinese translations in the merge, so removed them manually)

https://drive.google.com/open?id=1aBFFi6lF8lRna_RpA7TO5XSap8KFf4tL

(byebug) Node.first.flatten_hash(p).count
  CACHE Node Load (0.0ms)  SELECT  "node".* FROM "node" ORDER BY "node"."nid" ASC LIMIT ?  [["LIMIT", 1]]
875
(byebug) 

cc @jywarren

Completed in #4751. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

first-timers[bot] picture first-timers[bot]  路  3Comments

divyabaid16 picture divyabaid16  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments

jywarren picture jywarren  路  3Comments

keshavsethi picture keshavsethi  路  3Comments