OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Use non numeric string keys for translation
Christophe Bliard77519268f87b
diff --git a/app/seeders/source/filter_translatables.rb b/app/seeders/source/filter_translatables.rbindex 4304fbf8449..6c9e523fc59 100644--- a/app/seeders/source/filter_translatables.rb+++ b/app/seeders/source/filter_translatables.rb@@ -58,7 +58,7 @@ module Source::FilterTranslatablesdef filter_translatables_in_array(array, translatable: false)array.map.with_index.to_h do |value, i|- key = i.to_s+ key = "item_#{i}"if value.is_a?(Hash)[key, filter_translatables_in_object(value)]elsif translatablediff --git a/app/seeders/source/translate.rb b/app/seeders/source/translate.rbindex 5f86e58d716..e956ae96eb5 100644--- a/app/seeders/source/translate.rb+++ b/app/seeders/source/translate.rb@@ -57,7 +57,7 @@ module Source::Translatewhen StringI18n.t(i18n_key, locale:, default: value)when Array- value.map.with_index { |v, i| translate_value(v, "#{i18n_key}.#{i}") }+ value.map.with_index { |v, i| translate_value(v, "#{i18n_key}.item_#{i}") }endend@@ -69,7 +69,7 @@ module Source::Translatewhen Arrayvalue.filter { |v| v.is_a?(Hash) }- .each_with_index { |h, i| translate(h, "#{i18n_key}.#{key}.#{i}") }+ .each_with_index { |h, i| translate(h, "#{i18n_key}.#{key}.item_#{i}") }endendenddiff --git a/spec/seeders/source/filter_translatables_spec.rb b/spec/seeders/source/filter_translatables_spec.rbindex d2a8cc6873d..7f8d166e47e 100644--- a/spec/seeders/source/filter_translatables_spec.rb+++ b/spec/seeders/source/filter_translatables_spec.rb@@ -78,9 +78,9 @@ RSpec.describe Source::FilterTranslatables do}expect(loader.filter_translatables(hash)).to eq('categories' => {- '0' => 'First',- '1' => 'Second',- '2' => 'Third'+ 'item_0' => 'First',+ 'item_1' => 'Second',+ 'item_2' => 'Third'})end@@ -95,8 +95,8 @@ RSpec.describe Source::FilterTranslatables do}expect(loader.filter_translatables(hash)).to eq('categories' => {- '1' => { 'name' => 'kept as it is translatable' },- '2' => 'Kept too as the parent key is translatable'+ 'item_1' => { 'name' => 'kept as it is translatable' },+ 'item_2' => 'Kept too as the parent key is translatable'})end@@ -117,9 +117,9 @@ RSpec.describe Source::FilterTranslatables do}expect(loader.filter_translatables(hash)).to eq('categories' => {- '0' => { 'name' => 'First' },- '1' => { 'name' => 'Second' },- '3' => { 'name' => 'Fourth' }+ 'item_0' => { 'name' => 'First' },+ 'item_1' => { 'name' => 'Second' },+ 'item_3' => { 'name' => 'Fourth' }})enddiff --git a/spec/seeders/source/seed_data_loader_spec.rb b/spec/seeders/source/seed_data_loader_spec.rbindex 666d81745e8..08608016880 100644--- a/spec/seeders/source/seed_data_loader_spec.rb+++ b/spec/seeders/source/seed_data_loader_spec.rb@@ -127,8 +127,8 @@ RSpec.describe Source::SeedDataLoader doit 'translates each values using indices' domock_translations(locale,- "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.categories.0" => 'Erste Kategorie',- "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.categories.1" => 'Zweite Kategorie'+ "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.categories.item_0" => 'Erste Kategorie',+ "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.categories.item_1" => 'Zweite Kategorie')hash = {'t_categories' => [@@ -148,8 +148,8 @@ RSpec.describe Source::SeedDataLoader doit 'translates keys in the nested values if they have translatable keys' domock_translations(locale,- "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.queries.0.name" => 'Plan projet',- "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.queries.1.name" => 'Tâches'+ "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.queries.item_0.name" => 'Plan projet',+ "#{Source::Translate::I18N_PREFIX}.#{seed_file_name}.queries.item_1.name" => 'Tâches')translated = loader.translate(