summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorsyeopite <syeopite@syeopite.dev>2021-06-13 07:23:45 -0700
committersyeopite <syeopite@syeopite.dev>2021-06-13 07:23:45 -0700
commitd4327329596c7d07392896c61fb3aebf4acb7216 (patch)
tree0f6c9b82961dc76eb542add65696ed491ae6782c /scripts
parent4eb3de7b4e5f4fa27d4e61da247da258dfc1699e (diff)
downloadinvidious-d4327329596c7d07392896c61fb3aebf4acb7216.tar.gz
invidious-d4327329596c7d07392896c61fb3aebf4acb7216.tar.bz2
invidious-d4327329596c7d07392896c61fb3aebf4acb7216.zip
Add ability to propagate locale removals
Diffstat (limited to 'scripts')
-rw-r--r--scripts/propagate-new-locale-keys.cr22
1 files 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|