Skip to content

Instantly share code, notes, and snippets.

@zawyelwin
Last active September 3, 2020 18:41
Show Gist options
  • Save zawyelwin/789c802acc5f1fb9ba8513a93145c42a to your computer and use it in GitHub Desktop.
Save zawyelwin/789c802acc5f1fb9ba8513a93145c42a to your computer and use it in GitHub Desktop.
A Simple YAML flatten script with dot notation.
en:
questions:
new: 'New Question'
other:
recent: 'Recent'
old: 'Old'
require 'yaml'
require 'json'
require 'i18n'
yaml = YAML::load(STDIN.read);
include I18n::Backend::Flatten
puts JSON.pretty_generate flatten_translations(nil, yaml, nil, false)
@zawyelwin
Copy link
Author

zawyelwin commented Aug 25, 2020

Usage

$ gem install i18n
$ ruby yaml-flat.rb < test.yml 

Output

{
  "en.questions.new": "New Question",
  "en.questions.other.recent": "Recent",
  "en.questions.other.old": "Old"
}

@zawyelwin
Copy link
Author

zawyelwin commented Aug 25, 2020

Original Source : Stackoverflow - from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment