From d4327329596c7d07392896c61fb3aebf4acb7216 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sun, 13 Jun 2021 07:23:45 -0700 Subject: [PATCH] Add ability to propagate locale removals --- scripts/propagate-new-locale-keys.cr | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/propagate-new-locale-keys.cr b/scripts/propagate-new-locale-keys.cr index 39910c6e..570b408a 100644 --- a/scripts/propagate-new-locale-keys.cr +++ b/scripts/propagate-new-locale-keys.cr @@ -20,7 +20,7 @@ end # Invidious currently has some unloaded localization files. We shouldn't need to propagate new keys onto those. # We'll also remove the reference locale (english) from the list to process. loaded_locales = LOCALES.keys.select! { |key| key != "en-US" } -english_locale = locale_to_array("en-US")[0] +english_locale, english_locale_keys = locale_to_array("en-US") # In order to automatically propagate locale keys we're going to be needing two arrays. # One is an array containing each locale data encoded as tuples. The other would contain @@ -39,7 +39,8 @@ loaded_locales.each do |name| locale_list_with_only_keys << keys_only_locale end -locale_list_with_only_keys.each_with_index do |keys_of_locale_in_processing, index_of_locale_in_processing| +# Propagate additions +locale_list_with_only_keys.dup.each_with_index do |keys_of_locale_in_processing, index_of_locale_in_processing| insert_at = {} of Int32 => Tuple(String, JSON::Any | String) LOCALES["en-US"].each_with_index do |ref_locale_data, ref_locale_key_index| @@ -57,10 +58,27 @@ locale_list_with_only_keys.each_with_index do |keys_of_locale_in_processing, ind end insert_at.each do |location_to_insert, data| + locale_list_with_only_keys[index_of_locale_in_processing].insert(location_to_insert, data[0]) locale_list[index_of_locale_in_processing].insert(location_to_insert, data) end end +# Propagate removals +locale_list_with_only_keys.dup.each_with_index do |keys_of_locale_in_processing, index_of_locale_in_processing| + remove_at = [] of Int32 + + keys_of_locale_in_processing.each_with_index do |current_key, current_key_index| + if !english_locale_keys.includes? current_key + remove_at << current_key_index + end + end + + remove_at.each do |index_to_remove_at| + locale_list_with_only_keys[index_of_locale_in_processing].delete_at(index_to_remove_at) + locale_list[index_of_locale_in_processing].delete_at(index_to_remove_at) + end +end + # Now we convert back to our original format. final_locale_list = [] of String locale_list.each do |locale|