How do I recursively flatten a YAML file into a JSON object where keys are dot separated strings?
问题 For example if I have YAML file with en: questions: new: 'New Question' other: recent: 'Recent' old: 'Old' This would end up as a json object like { 'questions.new': 'New Question', 'questions.other.recent': 'Recent', 'questions.other.old': 'Old' } 回答1: Since the question is about using YAML files for i18n on a Rails app, it's worth noting that the i18n gem provides a helper module I18n::Backend::Flatten that flattens translations exactly like this: test.rb : require 'yaml' require 'json'