ruby - How can I sort YAML files? -


I am trying to sort a i18n translation YAML file with Ruby so that I can translate the new translation into a better translated way Can manage , But I was thinking that there is something to reduce the work.

I got a YAML file author, so I can write a hash in a file, but my problem is to sort the hash correctly if I got the hash h , < Code> h.sort gives an array and I still do not have an easy way to do this.

I have YAML files like this:

  pt-br: global: misc: total: "total" all: "todo" close: "fechar" Cancel : "Cancel" crud: access: "Acessar" back: "Voter" Edit: Confirm "Editors": Send "Confirmor": "Envir" ...   

(files

But I want to sort them out like this:

pt: br: global: crud: access: "Acessar" back: " Voltar "Confirm: Edit" Confirm ":" Editar "send:" Enviar "All": Cancel "Todos": Close "Cancel": "Feature" Total: "A I thought that some simple recursive methods can help me in this way: DR TranslationSource (H) if H. Class = = Hash H = H. source HK {| item | translation_sort (item)} end h and "yaml" h = YAML.load_file (file.open ("~ / pt-br.sample.yml") is required ) Translation_sort (h)

Actually this is a good question, you have a deep I do not like to invent the wheel again, and then I have a good Find good implementation and I found that I like. take a look at it . it works fine.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -