require 'yaml' require 'missing_translation/yaml_processor' module MissingTranslation class Util def self.uncommitted_changes? status = `git status --porcelain` return false if $CHILD_STATUS.success? && status.empty? error = if $CHILD_STATUS.success? "You have uncommitted code. Please commit or stash your changes before continuing" else "You do not have Git installed. Please install Git, and commit your changes before continuing" end p error true end def self.commit_all_changes(message) status = `git add .` status = system "git commit -m \"#{message}\"" end def self.sort_file(filepath) content = YAML.load_file(filepath) hash = MissingTranslation::YamlProcessor.denormalize_translations_hash(content) translations = MissingTranslation::YamlProcessor.normalize_translations_hash(hash) File.write(filepath, translations.to_yaml) end def self.sort(file_pattern = "./config/locales/#{file_extension}/*.yml") file_pathnames = Dir[file_pattern] return unless file_pathnames && file_pathnames.size > 0 file_pathnames.each do |filepath| sort_file(filepath) end end end end