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
[36269] Add "other" to pluralization rules for one (#9102)
Oliver Güntherdfe575ca9cd5
diff --git a/frontend/src/app/init-locale.ts b/frontend/src/app/init-locale.tsnew file mode 100644index 00000000000..66155d19c65--- /dev/null+++ b/frontend/src/app/init-locale.ts@@ -0,0 +1,50 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+//+++++export function initializeLocale() {+ const meta = document.querySelector('meta[name=openproject_initializer]') as HTMLMetaElement;+ I18n.locale = meta.dataset.locale || 'en';+ I18n.firstDayOfWeek = parseInt(meta.dataset.firstDayOfWeek!, 10);++ // Override the default pluralization function to allow+ // "other" to be used as a fallback for "one" in languages where one is not set+ // (japanese, for example)+ I18n.pluralization["default"] = function (count:number) {+ switch (count) {+ case 0:+ return ["zero", "other"];+ case 1:+ return ["one", "other"];+ default:+ return ["other"];+ }+ };++ return import(/* webpackChunkName: "locale" */ `../locales/${I18n.locale}.js`);+}\ No newline at end of filediff --git a/frontend/src/app/modules/common/i18n/i18n.service.ts b/frontend/src/app/modules/common/i18n/i18n.service.tsindex 8f4430a4afd..9412db54e16 100644--- a/frontend/src/app/modules/common/i18n/i18n.service.ts+++ b/frontend/src/app/modules/common/i18n/i18n.service.ts@@ -20,7 +20,7 @@ export interface GlobalI18n {locale:string;firstDayOfWeek:number;-+ pluralization:any;}interface ToNumberOptions {diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 5d18fa2f309..1bc55151435 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -6,6 +6,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';import {SentryReporter} from "core-app/sentry/sentry-reporter";import {whenDebugging} from "core-app/helpers/debug_output";import {enableReactiveStatesLogging} from "reactivestates";+import {initializeLocale} from "core-app/init-locale";(window as any).global = window;@@ -26,10 +27,6 @@ window.ErrorReporter = new SentryReporter();require('core-app/init-vendors');require('core-app/init-globals');-const meta = jQuery('meta[name=openproject_initializer]');-I18n.locale = meta.data('locale') || 'en';-I18n.firstDayOfWeek = parseInt(meta.data('firstDayOfWeek'), 10);-if (environment.production) {enableProdMode();}@@ -41,7 +38,7 @@ whenDebugging(() => {});// Import the correct locale early on-import(/* webpackChunkName: "locale" */ `./locales/${I18n.locale}.js`)+initializeLocale().then(() => {jQuery(function () {// Due to the behaviour of the Edge browser we need to wait for 'DOM ready'diff --git a/frontend/src/test/i18n-shim.ts b/frontend/src/test/i18n-shim.tsindex d86323ef090..e4ea1e5d241 100644--- a/frontend/src/test/i18n-shim.ts+++ b/frontend/src/test/i18n-shim.ts@@ -9,6 +9,8 @@ export class I18nShim implements GlobalI18n {en: {}};+ public pluralization = {};+t(key:string) {return '[missing "' + key + '" translation]';}diff --git a/modules/bim/spec/features/viewer/show_viewpoint_spec.rb b/modules/bim/spec/features/viewer/show_viewpoint_spec.rbindex 8dc0aa2dffc..0387f91d3ac 100644--- a/modules/bim/spec/features/viewer/show_viewpoint_spec.rb+++ b/modules/bim/spec/features/viewer/show_viewpoint_spec.rb@@ -60,12 +60,12 @@ describe 'Show viewpoint in model viewer',it 'loads the minimal viewpoint in the viewer' domodel_tree.select_sidebar_tab 'Objects'model_tree.expand_tree- model_tree.expect_checked 'minimal'retry_block do+ model_tree.expect_checked 'minimal'model_tree.all_checkboxes.each do |label, checkbox|expect_checked = (label.text == 'minimal' || label.text == 'LUB_Segment_new:S_WHG_Ess:7243035')if expect_checked != checkbox.checked?- raise "Expected #{label} to be #{expect_checked ? 'checked' : 'unchecked'}, but wasn't."+ raise "Expected #{label.text} to be #{expect_checked ? 'checked' : 'unchecked'}, but wasn't."endendend@@ -81,6 +81,10 @@ describe 'Show viewpoint in model viewer',context 'clicking on the card' dobefore do+ # We need to wait a bit for xeokit to be initialized+ # otherwise the viewpoint selection won't go through+ sleep 2+card_view.select_work_package work_packagecard_view.expect_work_package_selected work_package, trueend@@ -92,6 +96,10 @@ describe 'Show viewpoint in model viewer',before docard_view.open_full_screen_by_details work_packagebcf_details.expect_viewpoint_count 1++ # We need to wait a bit for xeokit to be initialized+ # otherwise the viewpoint selection won't go through+ sleep 2bcf_details.show_current_viewpointenddiff --git a/spec/features/support/components/time_logging_modal.rb b/spec/features/support/components/time_logging_modal.rbindex 47dd7f4e89b..aae6e8aaec7 100644--- a/spec/features/support/components/time_logging_modal.rb+++ b/spec/features/support/components/time_logging_modal.rb@@ -49,7 +49,7 @@ module Componentsif visiblewithin modal_container doexpect(page)- .to have_content(I18n.t('js.button_log_time'))+ .to have_text(I18n.t('js.button_log_time'))endelseexpect(page).to have_no_selector '.op-modal--modal-container'diff --git a/spec/features/work_packages/display_fields/spent_time_display_spec.rb b/spec/features/work_packages/display_fields/spent_time_display_spec.rbindex 9fc665dbdbe..9389ea4b6cf 100644--- a/spec/features/work_packages/display_fields/spent_time_display_spec.rb+++ b/spec/features/work_packages/display_fields/spent_time_display_spec.rb@@ -55,8 +55,8 @@ describe 'Logging time within the work package view', type: :feature, js: true dtime_logging_modal.update_field 'activity', activity.name# a click on save creates a time entry- time_logging_modal.perform_action 'Create'- wp_page.expect_and_dismiss_notification message: 'Successful creation.'+ time_logging_modal.perform_action I18n.t('js.label_create')+ wp_page.expect_and_dismiss_notification message: I18n.t(:notice_successful_create)endcontext 'as an admin' do@@ -87,44 +87,62 @@ describe 'Logging time within the work package view', type: :feature, js: true d# the value is updated automaticallyspent_time_field.expect_display_value '1 h'end- end- context 'as a user who cannot log time' do- before do- login_as(user_without_permissions)- wp_page.visit!- loading_indicator_saveguard+ context 'with a user with non-one unit numbers', with_settings: { available_languages: %w[en ja] } do+ let(:admin) { FactoryBot.create :admin, language: 'ja' }++ before do+ I18n.locale = 'ja'+ end++ it 'shows the correct number (Regression #36269)' do+ # click on button opens modal+ spent_time_field.open_time_log_modal++ log_time_via_modal++ # the value is updated automatically+ spent_time_field.expect_display_value '1 h'+ endend- it 'shows no logging button within the display field' do- spent_time_field.time_log_icon_visible false- spent_time_field.expect_display_value '-'+ context 'as a user who cannot log time' do+ before do+ login_as(user_without_permissions)+ wp_page.visit!+ loading_indicator_saveguard+ end++ it 'shows no logging button within the display field' do+ spent_time_field.time_log_icon_visible false+ spent_time_field.expect_display_value '-'+ endend- end- context 'within the table' do- let(:wp_table) { Pages::WorkPackagesTable.new(project) }- let(:second_work_package) { FactoryBot.create :work_package, project: project }- let(:query) { FactoryBot.create :public_query, project: project, column_names: ['subject', 'spent_hours'] }+ context 'within the table' do+ let(:wp_table) { Pages::WorkPackagesTable.new(project) }+ let(:second_work_package) { FactoryBot.create :work_package, project: project }+ let(:query) { FactoryBot.create :public_query, project: project, column_names: ['subject', 'spent_hours'] }- before do- work_package- second_work_package- login_as(admin)+ before do+ work_package+ second_work_package+ login_as(admin)- wp_table.visit_query query- loading_indicator_saveguard- end+ wp_table.visit_query query+ loading_indicator_saveguard+ end- it 'shows no logging button within the display field' do- wp_table.expect_work_package_listed work_package, second_work_package+ it 'shows no logging button within the display field' do+ wp_table.expect_work_package_listed work_package, second_work_package- find('tr:nth-of-type(1) .wp-table--cell-td.spentTime .icon-time').click+ find('tr:nth-of-type(1) .wp-table--cell-td.spentTime .icon-time').click- log_time_via_modal+ log_time_via_modal- expect(page).to have_selector('tr:nth-of-type(1) .wp-table--cell-td.spentTime', text: '1 h')- expect(page).to have_selector('tr:nth-of-type(2) .wp-table--cell-td.spentTime', text: '-')+ expect(page).to have_selector('tr:nth-of-type(1) .wp-table--cell-td.spentTime', text: '1 h')+ expect(page).to have_selector('tr:nth-of-type(2) .wp-table--cell-td.spentTime', text: '-')+ endendendend