From 0cdfc7cfbd9a94aea3e5373ab7c587217719d52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Fri, 30 Aug 2013 19:30:01 +0200 Subject: [PATCH] Make I18n systems more robust against missing keys in pluralization data Should make situations like #4468 less frequent --- Changelog.md | 1 + app/assets/javascripts/helpers/i18n.js | 10 +++++----- lib/i18n_interpolation_fallbacks.rb | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index b65b3b190..12a0a9eff 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ * Fix preview with more than one mention [#4450](https://github.com/diaspora/diaspora/issues/4450) * Fix size of images in the SPV [#4471](https://github.com/diaspora/diaspora/pull/4471) * Adjust 404 message description to not leak logged out users if a post exists or not [#4477](https://github.com/diaspora/diaspora/pull/4477) +* Make I18n system more robust against missing keys in pluralization data ## Features * Add oEmbed content to the mobile view [#4343](https://github.com/diaspora/diaspora/pull/4353) diff --git a/app/assets/javascripts/helpers/i18n.js b/app/assets/javascripts/helpers/i18n.js index 8a16e2ecf..79906c39f 100644 --- a/app/assets/javascripts/helpers/i18n.js +++ b/app/assets/javascripts/helpers/i18n.js @@ -20,6 +20,10 @@ translatedMessage, nextNamespace; + if(views && typeof views.count !== "undefined") { + items.push(this.pluralizationKey(views.count)); + } + while(nextNamespace = items.shift()) { translatedMessage = (translatedMessage) ? translatedMessage[nextNamespace] @@ -29,11 +33,7 @@ return ""; } } - - if(views && typeof views.count !== "undefined") { - translatedMessage = translatedMessage[this.pluralizationKey(views.count)]; - } - + return _.template(translatedMessage, views || {}); } }; diff --git a/lib/i18n_interpolation_fallbacks.rb b/lib/i18n_interpolation_fallbacks.rb index 096be511c..8b4d81e93 100644 --- a/lib/i18n_interpolation_fallbacks.rb +++ b/lib/i18n_interpolation_fallbacks.rb @@ -10,6 +10,7 @@ module I18n result = super(fallback, key, options) return result unless result.nil? rescue I18n::MissingInterpolationArgument + rescue I18n::InvalidPluralizationData end end