Skip to content

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

Send crowdin source file for seeders translations

Christophe Bliard9113c46f92fa
diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml
index 149e63239e1..9ee6a92b7a2 100644
--- a/.github/workflows/crowdin.yml
+++ b/.github/workflows/crowdin.yml
@@ -57,7 +57,10 @@ jobs:
else
echo "crowdin_branch=release" >> $GITHUB_OUTPUT
fi
- - name: "Updating translations"
+ - name: "Generate seeders i18n source file"
+ run: |
+ ruby script/i18n/generate_seeders_i18n_source_file
+ - name: "Crowdin: upload sources and download translations"
uses: crowdin/[email protected]
with:
# Upload current source files
diff --git a/.gitignore b/.gitignore
index e0b39c9aa46..a6dcbe37c69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -140,3 +140,6 @@ frontend/package-lock.json
# Testing and nextcloud infrastructure
acme.json
.env.test
+
+# Generated seeders crowdin source file
+**/config/locales/en.seeders.yml
diff --git a/app/seeders/root_seeder.rb b/app/seeders/root_seeder.rb
index 3d94e155477..8decf0da90a 100644
--- a/app/seeders/root_seeder.rb
+++ b/app/seeders/root_seeder.rb
@@ -41,7 +41,7 @@ class RootSeeder < Seeder
def seed_data
raise 'cannot generate demo seed data without setting locale first' unless @locale_set
- @seed_data ||= SeedDataLoader.get_data
+ @seed_data ||= Source::SeedDataLoader.get_data
end
def seed_data!
diff --git a/app/seeders/source/filter_translatables.rb b/app/seeders/source/filter_translatables.rb
new file mode 100644
index 00000000000..57170be5fc8
--- /dev/null
+++ b/app/seeders/source/filter_translatables.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Source::FilterTranslatables
+ def filter_translatables(hash)
+ filter_translatables_in_hash(hash) || {}
+ end
+
+ private
+
+ def filter_translatables_in_object(object, translatable: false)
+ case object
+ when Hash
+ filter_translatables_in_hash(object)
+ when Array
+ filter_translatables_in_array(object, translatable:)
+ else
+ object if translatable
+ end
+ end
+
+ def filter_translatables_in_hash(hash)
+ hash
+ .to_h do |key, value|
+ translatable = key.start_with?('t_')
+ [key.sub(/^t_/, ''), filter_translatables_in_object(value, translatable:)]
+ end
+ .compact
+ .presence
+ end
+
+ def filter_translatables_in_array(array, translatable: false)
+ array.map.with_index.to_h do |value, i|
+ if value.is_a?(Hash)
+ [i, filter_translatables_in_object(value)]
+ elsif translatable
+ [i, value]
+ else
+ [i, nil]
+ end
+ end
+ .compact
+ .presence
+ end
+end
diff --git a/app/seeders/seed_data.rb b/app/seeders/source/seed_data.rb
similarity index 95%
rename from app/seeders/seed_data.rb
rename to app/seeders/source/seed_data.rb
index e45b12ccb69..ba7c5547809 100644
--- a/app/seeders/seed_data.rb
+++ b/app/seeders/source/seed_data.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class SeedData
+class Source::SeedData
def initialize(data, registry = nil)
@data = data
@registry = registry || {}
@@ -52,7 +52,7 @@ class SeedData
def lookup(path)
case sub_data = fetch(path)
when Hash
- SeedData.new(sub_data, registry)
+ self.class.new(sub_data, registry)
else
sub_data
end
@@ -74,7 +74,7 @@ class SeedData
return if sub_data.nil?
sub_data.each_value do |item_data|
- yield SeedData.new(item_data, registry)
+ yield self.class.new(item_data, registry)
end
end
diff --git a/app/seeders/source/seed_data_loader.rb b/app/seeders/source/seed_data_loader.rb
new file mode 100644
index 00000000000..d89926a179c
--- /dev/null
+++ b/app/seeders/source/seed_data_loader.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class Source::SeedDataLoader
+ include Source::Translate
+
+ class << self
+ def get_data(edition: nil)
+ edition ||= OpenProject::Configuration['edition']
+ loader = new(seed_file_name: edition)
+ loader.seed_data
+ end
+ end
+
+ attr_reader :seed_file_name, :locale
+
+ def initialize(seed_file_name: 'standard', locale: I18n.locale)
+ @seed_file_name = seed_file_name
+ @locale = locale
+ end
+
+ def seed_data
+ @seed_data ||= Source::SeedData.new(translate(seed_file.raw_content))
+ end
+
+ private
+
+ def seed_file
+ Source::SeedFile.find(seed_file_name)
+ end
+end
diff --git a/app/seeders/source/seed_file.rb b/app/seeders/source/seed_file.rb
new file mode 100644
index 00000000000..f62e51d3db9
--- /dev/null
+++ b/app/seeders/source/seed_file.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class Source::SeedFile
+ class << self
+ def all
+ @all ||= [
+ new('app/seeders/standard.yml'),
+ new('modules/bim/app/seeders/bim.yml')
+ ].freeze
+ end
+
+ def find(name)
+ all.find { |f| f.name == name }
+ end
+ end
+
+ attr_reader :path
+
+ def initialize(path)
+ @path = Rails.root.join(path)
+ end
+
+ def name
+ path.basename(path.extname).to_s
+ end
+
+ def raw_content
+ YAML.load_file(path).deep_stringify_keys!
+ end
+end
diff --git a/app/seeders/seed_data_loader.rb b/app/seeders/source/translate.rb
similarity index 76%
rename from app/seeders/seed_data_loader.rb
rename to app/seeders/source/translate.rb
index 7dd9662adfe..5f86e58d716 100644
--- a/app/seeders/seed_data_loader.rb
+++ b/app/seeders/source/translate.rb
@@ -28,27 +28,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class SeedDataLoader
- class << self
- def get_data(edition: nil)
- edition ||= OpenProject::Configuration['edition']
- loader = new(edition:)
- loader.seed_data
- end
- end
-
- attr_reader :edition, :locale
+module Source::Translate
+ I18N_PREFIX = "seeds"
- def initialize(edition: 'standard', locale: I18n.locale)
- @edition = edition
- @locale = locale
- end
-
- def seed_data
- @seed_data ||= SeedData.new(translate(raw_seed_data))
- end
-
- def translate(hash, i18n_key = "seeds.#{edition}")
+ def translate(hash, i18n_key = "#{I18N_PREFIX}.#{seed_file_name}")
translate_translatable_keys(hash, i18n_key)
translate_nested_enumerations(hash, i18n_key)
hash
@@ -90,13 +73,4 @@ class SeedDataLoader
end
end
end
-
- def raw_seed_data
- YAML.load_file(seed_file_path).deep_stringify_keys!
- end
-
- def seed_file_path
- path = edition == 'bim' ? 'modules/bim/app/seeders/bim.yml' : 'app/seeders/standard.yml'
- Rails.root.join(path)
- end
end
diff --git a/app/seeders/standard.yml b/app/seeders/standard.yml
index b352a1455af..351d435cf82 100644
--- a/app/seeders/standard.yml
+++ b/app/seeders/standard.yml
@@ -55,7 +55,7 @@ projects:
- team_planner_view
news:
- t_title: Welcome to your demo project
- t_summary: >
+ t_summary: |
We are glad you joined.
In this module you can communicate project news to your team members.
t_description: The actual news
@@ -334,7 +334,7 @@ projects:
- board_view
news:
- t_title: Welcome to your Scrum demo project
- t_summary: >
+ t_summary: |
We are glad you joined.
In this module you can communicate project news to your team members.
description: This is the news content.
diff --git a/crowdin.yml b/crowdin.yml
index 375d1ece636..215fe218343 100644
--- a/crowdin.yml
+++ b/crowdin.yml
@@ -15,6 +15,10 @@ files: [
"source": "/config/locales/js-en.yml",
"translation": "/config/locales/crowdin/js-%two_letters_code%.yml",
},
+ {
+ "source": "/config/locales/en.seeders.yml",
+ "translation": "/config/locales/crowdin/%two_letters_code%.seeders.yml",
+ },
{
"source": "/modules/**/config/locales/en.yml",
"translation": "/modules/**/config/locales/crowdin/%two_letters_code%.yml",
@@ -23,4 +27,8 @@ files: [
"source": "/modules/**/config/locales/js-en.yml",
"translation": "/modules/**/config/locales/crowdin/js-%two_letters_code%.yml",
},
+ {
+ "source": "/modules/**/config/locales/en.seeders.yml",
+ "translation": "/modules/**/config/locales/crowdin/%two_letters_code%.seeders.yml",
+ },
]
diff --git a/modules/bim/app/seeders/bim.yml b/modules/bim/app/seeders/bim.yml
index d71c21cc10c..88c6224390d 100644
--- a/modules/bim/app/seeders/bim.yml
+++ b/modules/bim/app/seeders/bim.yml
@@ -93,7 +93,7 @@ projects:
- team_planner_view
news:
- t_title: Welcome to your demo project
- t_summary: >
+ t_summary: |
We are glad you joined.
In this module you can communicate project news to your team members.
t_description: The actual news
@@ -240,7 +240,7 @@ projects:
- team_planner_view
news:
- t_title: Welcome to your demo project
- t_summary: >
+ t_summary: |
We are glad you joined.
In this module you can communicate project news to your team members.
t_description: The actual news
@@ -707,7 +707,7 @@ projects:
- team_planner_view
news:
- t_title: Welcome to your demo project
- t_summary: >
+ t_summary: |
We are glad you joined.
In this module you can communicate project news to your team members.
t_description: The actual news
diff --git a/script/i18n/generate_seeders_i18n_source_file b/script/i18n/generate_seeders_i18n_source_file
new file mode 100755
index 00000000000..89d3f38dd5a
--- /dev/null
+++ b/script/i18n/generate_seeders_i18n_source_file
@@ -0,0 +1,92 @@
+#!/usr/bin/env ruby
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+if !defined? Rails
+ warn 'Error: this script must be run with `rails runner`'
+ warn ''
+ warn "Try running: bundle exec rails runner #{$0}"
+ exit 1
+end
+
+class GenerateSeederSourceTranslationFiles
+ class << self
+ include Source::FilterTranslatables
+
+ def call
+ Source::SeedFile.all.each do |seed_file|
+ create_crowdin_source_file(seed_file)
+ end
+ puts "Done"
+ end
+
+ def create_crowdin_source_file(seed_file)
+ source_file_path(seed_file.path).open('w') do |f|
+ puts "Generate crowdin source file #{relative_path(f.path)}"
+
+ f.puts comment
+ YAML.dump(translatable_data(seed_file), f)
+ end
+ end
+
+ def source_file_path(seed_file_path)
+ base_path = seed_file_path
+ loop do
+ base_path, dir = base_path.split
+ break if dir.to_s == 'app'
+ end
+ base_path.join('config/locales/en.seeders.yml')
+ end
+
+ def comment
+ <<~COMMENT.freeze
+ # This file has been generated by #{relative_path($0)}.
+ # Please do not edit directly.
+ #
+ # This file is part of the sources sent to crowdin for translation.
+ COMMENT
+ end
+
+ def translatable_data(seed_file)
+ {
+ 'en' => {
+ Source::Translate::I18N_PREFIX => {
+ seed_file.name => filter_translatables(seed_file.raw_content)
+ }
+ }
+ }
+ end
+
+ def relative_path(path)
+ Pathname.new(path).relative_path_from(Rails.root).to_s
+ end
+ end
+end
+
+GenerateSeederSourceTranslationFiles.call
diff --git a/spec/seeders/admin_user_seeder_spec.rb b/spec/seeders/admin_user_seeder_spec.rb
index b80fdd9d9d3..30dcbabad5f 100644
--- a/spec/seeders/admin_user_seeder_spec.rb
+++ b/spec/seeders/admin_user_seeder_spec.rb
@@ -33,7 +33,7 @@ require 'spec_helper'
RSpec.describe AdminUserSeeder do
subject(:seeder) { described_class.new(seed_data) }
- let(:seed_data) { SeedData.new({}) }
+ let(:seed_data) { Source::SeedData.new({}) }
it 'creates an admin user' do
expect { seeder.seed! }.to change { User.admin.count }.by(1)
diff --git a/spec/seeders/basic_data/type_seeder_spec.rb b/spec/seeders/basic_data/type_seeder_spec.rb
index 9c445818e2b..b91d9878d75 100644
--- a/spec/seeders/basic_data/type_seeder_spec.rb
+++ b/spec/seeders/basic_data/type_seeder_spec.rb
@@ -34,7 +34,7 @@ RSpec.describe BasicData::TypeSeeder do
subject(:seeder) { described_class.new(seed_data) }
let(:phase_type) { create(:type, name: I18n.t(:default_type_phase)) }
- let(:seed_data) { SeedData.new(data_hash) }
+ let(:seed_data) { Source::SeedData.new(data_hash) }
before do
phase_type # create the Phase type
diff --git a/spec/seeders/demo_data/global_query_seeder_spec.rb b/spec/seeders/demo_data/global_query_seeder_spec.rb
index b478dc6378f..1bc2b203990 100644
--- a/spec/seeders/demo_data/global_query_seeder_spec.rb
+++ b/spec/seeders/demo_data/global_query_seeder_spec.rb
@@ -33,7 +33,7 @@ require 'spec_helper'
RSpec.describe DemoData::GlobalQuerySeeder do
subject(:seeder) { described_class.new(seed_data) }
- let(:seed_data) { SeedData.new(data_hash) }
+ let(:seed_data) { Source::SeedData.new(data_hash) }
before do
AdminUserSeeder.new(seed_data).seed!
diff --git a/spec/seeders/demo_data/group_seeder_spec.rb b/spec/seeders/demo_data/group_seeder_spec.rb
index 6dc742cda7f..dfbd2171793 100644
--- a/spec/seeders/demo_data/group_seeder_spec.rb
+++ b/spec/seeders/demo_data/group_seeder_spec.rb
@@ -33,7 +33,7 @@ require 'spec_helper'
RSpec.describe DemoData::GroupSeeder do
subject(:seeder) { described_class.new(seed_data) }
- let(:seed_data) { SeedData.new(data_hash) }
+ let(:seed_data) { Source::SeedData.new(data_hash) }
context 'with a group defined' do
let(:data_hash) do
diff --git a/spec/seeders/demo_data/project_seeder_spec.rb b/spec/seeders/demo_data/project_seeder_spec.rb
index 4899d1a9048..e331b50db1d 100644
--- a/spec/seeders/demo_data/project_seeder_spec.rb
+++ b/spec/seeders/demo_data/project_seeder_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe DemoData::ProjectSeeder do
].each { |seeder| seeder.new.seed! }
end
- let(:seed_data) { SeedData.new(project_data) }
+ let(:seed_data) { Source::SeedData.new(project_data) }
let(:project_data) { project_data_with_a_version }
let(:project_data_with_a_version) do
{
diff --git a/spec/seeders/demo_data/work_package_seeder_spec.rb b/spec/seeders/demo_data/work_package_seeder_spec.rb
index 528cd5500c0..759437a0641 100644
--- a/spec/seeders/demo_data/work_package_seeder_spec.rb
+++ b/spec/seeders/demo_data/work_package_seeder_spec.rb
@@ -50,7 +50,7 @@ describe DemoData::WorkPackageSeeder do
let(:new_project_role) { Role.find_by(name: I18n.t(:default_role_project_admin)) }
let(:closed_status) { Status.find_by(name: I18n.t(:default_status_closed)) }
let(:work_packages_data) { [] }
- let(:seed_data) { SeedData.new('work_packages' => work_packages_data) }
+ let(:seed_data) { Source::SeedData.new('work_packages' => work_packages_data) }
def work_package_data(**attributes)
{
@@ -283,7 +283,7 @@ describe DemoData::WorkPackageSeeder do
context 'with a work package description referencing a query with ##query:ref notation' do
let(:seed_data) do
- seed_data = SeedData.new('work_packages' => work_packages_data)
+ seed_data = Source::SeedData.new('work_packages' => work_packages_data)
seed_data.store_reference(:q_project_plan, query)
seed_data
end
@@ -303,7 +303,7 @@ describe DemoData::WorkPackageSeeder do
context 'with a work package description referencing a sprint with ##sprint:ref notation' do
let(:seed_data) do
- seed_data = SeedData.new('work_packages' => work_packages_data)
+ seed_data = Source::SeedData.new('work_packages' => work_packages_data)
seed_data.store_reference(:sprint_backlog, sprint)
seed_data
end
@@ -323,7 +323,7 @@ describe DemoData::WorkPackageSeeder do
describe 'assigned_to' do
let(:seed_data) do
- seed_data = SeedData.new('work_packages' => work_packages_data)
+ seed_data = Source::SeedData.new('work_packages' => work_packages_data)
seed_data.store_reference(:user_bernard, a_user)
seed_data
end
diff --git a/spec/seeders/seeder_spec.rb b/spec/seeders/seeder_spec.rb
index 9636292f0ce..dcabc54aaf7 100644
--- a/spec/seeders/seeder_spec.rb
+++ b/spec/seeders/seeder_spec.rb
@@ -33,7 +33,7 @@ require 'spec_helper'
RSpec.describe Seeder do
subject(:seeder) { described_class.new }
- let(:seed_data) { SeedData.new({}) }
+ let(:seed_data) { Source::SeedData.new({}) }
describe '#user' do
it 'returns the admin created from the seeding' do
diff --git a/spec/seeders/source/filter_translatables_spec.rb b/spec/seeders/source/filter_translatables_spec.rb
new file mode 100644
index 00000000000..f40dc0a49e3
--- /dev/null
+++ b/spec/seeders/source/filter_translatables_spec.rb
@@ -0,0 +1,176 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+RSpec.describe Source::FilterTranslatables do
+ subject(:loader) do
+ described_module = described_class
+ Class.new do
+ include described_module
+ end.new
+ end
+
+ describe '#filter_translatables' do
+ it 'keeps only keys with t_ prefix' do
+ hash = {
+ 't_title' => 'Welcome to OpenProject',
+ 't_text' => 'Learn how to plan projects efficiently.',
+ 'icon' => ':smile:'
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'title' => 'Welcome to OpenProject',
+ 'text' => 'Learn how to plan projects efficiently.'
+ )
+ end
+
+ it 'does not alter names of keys having "t_" in their names' do
+ hash = {
+ 'welcome_at_home' => {
+ 't_title' => 'Welcome to OpenProject',
+ 't_text' => 'Learn how to plan projects efficiently.',
+ 'icon' => ':smile:'
+ }
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'welcome_at_home' => {
+ 'title' => 'Welcome to OpenProject',
+ 'text' => 'Learn how to plan projects efficiently.'
+ }
+ )
+ end
+
+ it 'replaces translatable arrays with hashes indexed by array position' do
+ hash = {
+ 't_categories' => [
+ 'First',
+ 'Second',
+ 'Third'
+ ],
+ 'allowed_values' => ['yes', 'no']
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'categories' => {
+ 0 => 'First',
+ 1 => 'Second',
+ 2 => 'Third'
+ }
+ )
+ end
+
+ it 'consider translatables only at the first level' do
+ hash = {
+ 't_categories' => [
+ { 'name' => 'discarded as it is not translatable' },
+ { 't_name' => 'kept as it is translatable' },
+ 'Kept too as the parent key is translatable'
+ ]
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'categories' => {
+ 1 => { 'name' => 'kept as it is translatable' },
+ 2 => 'Kept too as the parent key is translatable'
+ }
+ )
+ end
+
+ it 'replaces arrays of translatables with hashes indexed by array position' do
+ hash = {
+ 'categories' => [
+ {
+ 't_name' => 'First'
+ }, {
+ 't_name' => 'Second'
+ }, {
+ 'name' => 'This one is discarded as it is not translatable (no t_ prefix)'
+ }, {
+ 't_name' => 'Fourth'
+ }
+ ]
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'categories' => {
+ 0 => { 'name' => 'First' },
+ 1 => { 'name' => 'Second' },
+ 3 => { 'name' => 'Fourth' }
+ }
+ )
+ end
+
+ it 'discards empty arrays and hashes' do
+ hash = {
+ 'categories' => [],
+ 'main' => {},
+ 'work_packages' => [
+ {
+ 'custom_values' => {}
+ }
+ ],
+ 'meta' => {
+ 'allowed_values' => []
+ }
+ }
+ expect(loader.filter_translatables(hash)).to eq({})
+ end
+
+ it 'keeps nested structures having translatable keys inside it' do
+ hash = {
+ 'welcome' => {
+ 't_title' => 'Welcome to OpenProject',
+ 't_text' => 'Learn how to plan projects efficiently.',
+ 'icon' => ':smile:'
+ }
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'welcome' => {
+ 'title' => 'Welcome to OpenProject',
+ 'text' => 'Learn how to plan projects efficiently.'
+ }
+ )
+ end
+
+ it 'rejects nested structures without any translatable keys inside it' do
+ hash = {
+ 'welcome' => {
+ 't_title' => 'Welcome to OpenProject'
+ },
+ 'position' => {
+ 'x' => 18,
+ 'y' => 76
+ }
+ }
+ expect(loader.filter_translatables(hash)).to eq(
+ 'welcome' => {
+ 'title' => 'Welcome to OpenProject'
+ }
+ )
+ end
+ end
+end
diff --git a/spec/seeders/seed_data_loader_spec.rb b/spec/seeders/source/seed_data_loader_spec.rb
similarity index 90%
rename from spec/seeders/seed_data_loader_spec.rb
rename to spec/seeders/source/seed_data_loader_spec.rb
index fd814f08781..9ddbb2b88a3 100644
--- a/spec/seeders/seed_data_loader_spec.rb
+++ b/spec/seeders/source/seed_data_loader_spec.rb
@@ -30,7 +30,7 @@
require 'spec_helper'
-RSpec.describe SeedDataLoader do
+RSpec.describe Source::SeedDataLoader do
let(:title_en) { 'Welcome to OpenProject' }
let(:text_en) { 'Learn how to plan projects efficiently.' }
let(:title_fr) { 'Bienvenue sur OpenProject' }
@@ -52,8 +52,8 @@ RSpec.describe SeedDataLoader do
loader = described_class.new(locale: 'fr')
mock_translations(
'fr',
- 'seeds.standard.welcome.title' => title_fr,
- 'seeds.standard.welcome.text' => text_fr
+ "#{Source::Translate::I18N_PREFIX}.standard.welcome.title" => title_fr,
+ "#{Source::Translate::I18N_PREFIX}.standard.welcome.text" => text_fr
)
hash = {
'welcome' => {
@@ -122,8 +122,8 @@ RSpec.describe SeedDataLoader do
loader = described_class.new(locale: 'de')
mock_translations(
'de',
- 'seeds.standard.categories.0' => 'Erste Kategorie',
- 'seeds.standard.categories.1' => 'Zweite Kategorie'
+ "#{Source::Translate::I18N_PREFIX}.standard.categories.0" => 'Erste Kategorie',
+ "#{Source::Translate::I18N_PREFIX}.standard.categories.1" => 'Zweite Kategorie'
)
hash = {
't_categories' => [
@@ -144,8 +144,8 @@ RSpec.describe SeedDataLoader do
loader = described_class.new(locale: 'fr')
mock_translations(
'fr',
- 'seeds.standard.queries.0.name' => 'Plan projet',
- 'seeds.standard.queries.1.name' => 'Tâches'
+ "#{Source::Translate::I18N_PREFIX}.standard.queries.0.name" => 'Plan projet',
+ "#{Source::Translate::I18N_PREFIX}.standard.queries.1.name" => 'Tâches'
)
translated = loader.translate(
diff --git a/spec/seeders/seed_data_spec.rb b/spec/seeders/source/seed_data_spec.rb
similarity index 98%
rename from spec/seeders/seed_data_spec.rb
rename to spec/seeders/source/seed_data_spec.rb
index 6b1ccd92ced..92e5f2e2c1a 100644
--- a/spec/seeders/seed_data_spec.rb
+++ b/spec/seeders/source/seed_data_spec.rb
@@ -30,7 +30,7 @@
require 'spec_helper'
-RSpec.describe SeedData do
+RSpec.describe Source::SeedData do
subject(:seed_data) { described_class.new({}) }
describe '#store_reference / find_reference' do