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 I have YAML files like this: (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: 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. h , < Code> h.sort gives an array and I still do not have an easy way to do this.
pt-br: global: misc: total: "total" all: "todo" close: "fechar" Cancel : "Cancel" crud: access: "Acessar" back: "Voter" Edit: Confirm "Editors": Send "Confirmor": "Envir" ...
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)
Comments
Post a Comment