From 9e51d51f2e4f07a3abc7106100f229dce8be04ac Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 9 May 2024 11:54:22 -0700 Subject: [PATCH] Remove unused YML file flatten helpers - Used to help address merge conflicts and streamline transition to flattened YML files, but should not be needed after changelog: Internal, Source code, Remove unused scripts --- scripts/merge_yml | 14 --------- scripts/yml_fix_merge_conflicts | 51 --------------------------------- scripts/yml_to_flat_yml | 49 ------------------------------- 3 files changed, 114 deletions(-) delete mode 100755 scripts/merge_yml delete mode 100755 scripts/yml_fix_merge_conflicts delete mode 100755 scripts/yml_to_flat_yml diff --git a/scripts/merge_yml b/scripts/merge_yml deleted file mode 100755 index f85b037b4fd..00000000000 --- a/scripts/merge_yml +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# Merges YML files, in order of least to greatest precedence -# Intended to only be used for flat yml file migration for translations -require 'yaml' - -first, *rest = ARGV - -combined = rest.reduce(YAML.load_file(first) || {}) do |accumulator, path| - accumulator.merge(YAML.load_file(path) || {}) -end - -puts combined.to_yaml diff --git a/scripts/yml_fix_merge_conflicts b/scripts/yml_fix_merge_conflicts deleted file mode 100755 index 618555052cd..00000000000 --- a/scripts/yml_fix_merge_conflicts +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -set -xeuo pipefail - -# Script to help fix merge conflicts when migrating to the flat yml style -# Run it after doing a `git merge origin/main` into a feature branch - -# Intended to be a temporary script only for flat yml migration - -# git checkout origin/main -- config/locales/ - -locales="en es fr zh" - -function find_locale_files() { - locale=$1 - - find config/locales -type f -name "*${locale}.yml" | \ - grep -v telephony | \ - grep -v transliterate -} - -for locale in $locales; do - find_locale_files "$locale" | - xargs ./scripts/yml_to_flat_yml > "tmp/newer_${locale}.yml" - - if [ -f "config/locales/${locale}.yml" ]; then - cp "config/locales/${locale}.yml" "tmp/older_${locale}.yml" - else - echo > "tmp/older_${locale}.yml" - fi - - ./scripts/merge_yml \ - "tmp/older_${locale}.yml" \ - "tmp/newer_${locale}.yml" \ - > "config/locales/${locale}.yml" -done - -if [[ "${1:-}" == "--force" ]]; then - git status --porcelain | grep "DU " | cut -d' ' -f 2 | xargs git rm - - for locale in $locales; do - find_locale_files "$locale" | \ - grep -v "config/locales/${locale}.yml" | \ - xargs git rm -f - done -fi - -make normalize_yaml - -for locale in $locales; do - git add "config/locales/${locale}.yml" -done diff --git a/scripts/yml_to_flat_yml b/scripts/yml_to_flat_yml deleted file mode 100755 index 90443675c37..00000000000 --- a/scripts/yml_to_flat_yml +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# Script to help migrating i18n files to our "flat yml" format -# Can probably be removed after migration is complete - -require 'yaml' -require 'json' - -combined = {} - -# @yieldparam keypath [Array] -# @yieldparam value -def each_full_key(obj, keypath: [], &block) - if obj.is_a?(Hash) - obj.each do |key, value| - each_full_key(value, keypath: keypath + [key], &block) - end - elsif obj.is_a?(Array) - obj.each_with_index do |item, idx| - each_full_key(item, keypath: keypath + [idx], &block) - end - else - yield keypath, obj - end -end - -if ARGV.empty? - puts <<~EOS - Usage: - - #{File.basename($PROGRAM_NAME)} FILE [OTHER...] - - Takes each YAML file provided as an argument, combines them into one hash - and "flattens" the keys - EOS - - exit 1 -end - -ARGV.each do |filename| - each_full_key(YAML.load_file(filename)) do |(_locale, *keypath), value| - combined[keypath.map(&:to_s).join('.')] = value - end -end - -combined.sort_by { |k, _v| k }.each do |flat_key, value| - STDOUT.puts "#{flat_key}: #{value.to_json}" if !flat_key.empty? -end