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
Add patch to I18n to replace empty strings with nil (#9068)
Oliver Günther6fde8cc32a36
diff --git a/frontend/src/app/modules/common/i18n/i18n.service.ts b/frontend/src/app/modules/common/i18n/i18n.service.tsindex d741feeae2c..8f4430a4afd 100644--- a/frontend/src/app/modules/common/i18n/i18n.service.ts+++ b/frontend/src/app/modules/common/i18n/i18n.service.ts@@ -52,10 +52,7 @@ export class I18nService {}public t(translateId:string, parameters?:{ [key:string]:any }):string {- // Avoid returning empty translation strings and fall back to english instead- // due to translation bugs- return this._i18n.t(translateId, parameters) ||- this._i18n.t(translateId, { ...parameters, locale: 'en' });+ return this._i18n.t(translateId, parameters);}public lookup(translateId:string):boolean|undefined {diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 12e8f1251eb..5d18fa2f309 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -41,12 +41,7 @@ whenDebugging(() => {});// Import the correct locale early on-Promise.all([- // untyped module cannot be dynamically imported- // @ts-ignore- import(/* webpackChunkName: "default-locale" */ `./locales/en.js`),- import(/* webpackChunkName: "locale" */ `./locales/${I18n.locale}.js`),-])+import(/* webpackChunkName: "locale" */ `./locales/${I18n.locale}.js`).then(() => {jQuery(function () {// Due to the behaviour of the Edge browser we need to wait for 'DOM ready'diff --git a/lib/open_project/patches.rb b/lib/open_project/patches.rbnew file mode 100644index 00000000000..7832090be86--- /dev/null+++ b/lib/open_project/patches.rb@@ -0,0 +1,48 @@+# encoding: utf-8++#-- 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.+#++++module OpenProject+ module Patches+ module_function++ ##+ # Check against a particular gem version+ # before patching it+ def patch_gem_version(gem, version, &block)+ found_version = Gem.loaded_specs[gem].version+ if found_version > Gem::Version.new(version)+ raise "OpenProject expects to patch gem '#{gem}' at version #{version} " \+ "but found version #{found_version.to_s}. Please check whether the patch is still valid."+ end++ block.call+ end+ end+enddiff --git a/lib/open_project/patches/carrierwave_sanitized_file.rb b/lib/open_project/patches/carrierwave_sanitized_file.rbindex 783fa4ed791..c2b05850b30 100644--- a/lib/open_project/patches/carrierwave_sanitized_file.rb+++ b/lib/open_project/patches/carrierwave_sanitized_file.rb@@ -6,10 +6,6 @@ require 'carrierwave/storage/fog'## @todo Upgrade to CarrierWave 2.0.2 to make this patch obsolete.-if Gem.loaded_specs["carrierwave"].version > Gem::Version.new('1.3.2')- raise "Check if these patches of Carrierwave are still required"-end-module OpenProject::Patches::FogFileextend ActiveSupport::Concern@@ -41,4 +37,6 @@ module OpenProject::Patches::FogFileendend-CarrierWave::Storage::Fog::File.include OpenProject::Patches::FogFile+OpenProject::Patches.patch_gem_version 'carrierwave', '1.3.2' do+ CarrierWave::Storage::Fog::File.include OpenProject::Patches::FogFile+enddiff --git a/lib/open_project/patches/declarative_option.rb b/lib/open_project/patches/declarative_option.rbindex 5335a60883a..23456d7d5fb 100644--- a/lib/open_project/patches/declarative_option.rb+++ b/lib/open_project/patches/declarative_option.rb@@ -41,10 +41,8 @@ module OpenProject::Patches::DeclarativeOptionendend-unless Declarative::Option.included_modules.include?(OpenProject::Patches::DeclarativeOption)- if Gem.loaded_specs['declarative-option'].version > Gem::Version.create('0.1.0')- raise "Check whether the patch to Declarative::Option is still necessary"+OpenProject::Patches.patch_gem_version 'declarative-option', '0.1.0' do+ unless Declarative::Option.included_modules.include?(OpenProject::Patches::DeclarativeOption)+ Declarative::Option.include OpenProject::Patches::DeclarativeOptionend-- Declarative::Option.include OpenProject::Patches::DeclarativeOptionenddiff --git a/lib/open_project/patches/fog_file.rb b/lib/open_project/patches/fog_file.rbindex 9b32c56a391..97b88b9416c 100644--- a/lib/open_project/patches/fog_file.rb+++ b/lib/open_project/patches/fog_file.rb@@ -1,7 +1,3 @@-if Gem.loaded_specs["carrierwave"].version > Gem::Version.new('1.3.2')- raise "Check if these patches of Carrierwave are still required"-end-module OpenProject::Patches::CarrierwaveSanitizedFileextend ActiveSupport::Concern@@ -16,4 +12,6 @@ module OpenProject::Patches::CarrierwaveSanitizedFileendend-CarrierWave::SanitizedFile.include OpenProject::Patches::CarrierwaveSanitizedFile+OpenProject::Patches.patch_gem_version 'carrierwave', '1.3.2' do+ CarrierWave::SanitizedFile.include OpenProject::Patches::CarrierwaveSanitizedFile+enddiff --git a/lib/open_project/patches/i18n_reject_empty_string.rb b/lib/open_project/patches/i18n_reject_empty_string.rbnew file mode 100644index 00000000000..bd5b1013b73--- /dev/null+++ b/lib/open_project/patches/i18n_reject_empty_string.rb@@ -0,0 +1,64 @@+#-- 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.+#++++module OpenProject+ module Patches+ ##+ # Crowdin currently breaks some of our pluralized strings+ # in locales other than the english source.+ #+ # Strings are being downloaded with an empty string as value despite+ # showing up correctly in their UI.+ #+ # This results in the fallback not properly working as it's not checking+ # for empty strings.+ #+ # This patch removes empty string values from the loaded YML before they+ # are being processed by fallbacks. With it, english fallbacks can be used automatically.+ # https://community.openproject.com/wp/36304+ module I18nRejectEmptyString+ def load_yml(filename)+ replace_empty_strings super+ end++ def replace_empty_strings(hash)+ hash.deep_transform_values do |value|+ if value == ''+ nil+ else+ value+ end+ end+ end+ end+ end+end++OpenProject::Patches.patch_gem_version 'i18n', '1.8.8' do+ I18n.backend.singleton_class.prepend OpenProject::Patches::I18nRejectEmptyString+end