Permalink
Browse files

Changed approach to use array of strings in the event plurals are nee…

…ded to not restrict the use of punctuation signs in the strings
  • Loading branch information...
1 parent 75389f4 commit 356dcb5eb7a037e379fb7c8d5b15d2c831459c0f @ron666 ron666 committed Oct 7, 2016
Showing with 19 additions and 20 deletions.
  1. +4 −5 guidelines.md
  2. +3 −3 src/js/me-i18n-locale-en.js
  3. +2 −2 src/js/me-i18n-locale-es.js
  4. +10 −10 src/js/me-i18n.js
View
@@ -72,8 +72,8 @@ If it is a translation that wants to be added, a couple of considerations need t
* The current format is `'mejs.[ID of element]' : 'translation'` (i.e., `'mejs.play': 'Play'`).
* The first element in the object **MUST** be `mejs.plural-form: [Number]`, where `[Number]` is the Family Group Number the language belongs (see `/src/js/me-18n.js` to determine which number is the appropriate one).
-* If you require to place a string with a plural, you must write the possible translations in the order specified in http://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html as a semi-colon separated string, and the placeholder to replace the number would be `%1`.
-* **Only one** plural can be in the string.
+* If you require to use plurals, you must write the possible translations in the order specified in http://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html as an array, and the placeholder to replace the number would be `%1`.
+* **Only one** plural can be in the strings.
* A code template to build a translation is presented below.
```javascript
/*!
@@ -95,10 +95,9 @@ If it is a translation that wants to be added, a couple of considerations need t
...
// Example for pluralization following the form `nplurals=3; plural=(n%10==1 ? 0 : n%10==2 ? 1 : 2);`
- // meaning that if the modulo between number indicated and 10 is 1, then the first string before the first
- // semi-colon will be used;
+ // meaning that if the modulo between number indicated and 10 is 1, then the first string will be used;
// if the modulo between number indicated and 10 is 2, it will use the second one; otherwise, it will use the third case
- 'mejs.time-skip-back' : "Назад на %1 секунд;Назад на %1 секунди;Назад на %1 секунда",
+ 'mejs.time-skip-back' : ["Назад на %1 секунд", "Назад на %1 секунди", "Назад на %1 секунда"],
};
}
@@ -37,7 +37,7 @@
'mejs.fullscreen' : 'Fullscreen',
// mep-feature-jumpforward
- 'mejs.time-jump-forward': 'Jump forward 1 second;Jump forward %1 seconds',
+ 'mejs.time-jump-forward': ['Jump forward 1 second', 'Jump forward %1 seconds'],
// mep-feature-playpause
'mejs.play': 'Play',
@@ -51,7 +51,7 @@
'mejs.time-help-text': 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.',
// mep-feature-skipback
- 'mejs.time-skip-back': 'Skip back 1 second;Skip back %1 seconds',
+ 'mejs.time-skip-back': ['Skip back 1 second', 'Skip back %1 seconds'],
// mep-feature-tracks
'mejs.captions-subtitles' : 'Captions/Subtitles',
@@ -70,7 +70,7 @@
// mep-feature-ads
'mejs.ad-skip': 'Skip ad',
- 'mejs.ad-skip-info': 'Skip in 1 second;Skip in %1 seconds',
+ 'mejs.ad-skip-info': ['Skip in 1 second', 'Skip in %1 seconds'],
'mejs.source-chooser': 'Source Chooser'
};
@@ -21,7 +21,7 @@
'mejs.plural-form': 1,
'mejs.ad-skip': "Saltar publicidad",
- 'mejs.ad-skip-info': "Saltar 1 segundo;Saltar %1 segundos",
+ 'mejs.ad-skip-info': ["Saltar 1 segundo", "Saltar %1 segundos"],
'mejs.audio-player' : "Reproductor de audio",
'mejs.captions-subtitles' : "Leyendas/Subtítulos",
'mejs.close' : "Cerrar",
@@ -36,7 +36,7 @@
'mejs.pause' : "Pausa",
'mejs.play' : "Reproducción",
'mejs.time-help-text' : "Use las flechas Izquierda/Derecha para avanzar un segundo y las flechas Arriba/Abajo para avanzar diez segundos.",
- 'mejs.time-skip-back' : "Rebobinar 1 segundo;Rebobinar %1 segundos",
+ 'mejs.time-skip-back' : ["Rebobinar 1 segundo", "Rebobinar %1 segundos"],
'mejs.time-slider' : "Control deslizante de tiempo",
'mejs.unmute' : "Reactivar silencio",
'mejs.video-player' : "Reproductor de video",
View
@@ -316,26 +316,26 @@
*
* @private
* @see http://stackoverflow.com/questions/1353408/messageformat-in-javascript-parameters-in-localized-ui-strings
- * @param {String} text - Semi-colon (;) separated string of words to pick the plural form
- * @param {Number} number - Number to determine the proper plural form
- * @param {Number} form - Number of language family to apply plural form
+ * @param {String|String[]} input - String or array of strings to pick the plural form
+ * @param {Number} number - Number to determine the proper plural form
+ * @param {Number} form - Number of language family to apply plural form
* @return {String}
*/
- plural = function (text, number, form) {
+ plural = function (input, number, form) {
- if (typeof text !== 'string' || typeof number !== 'number' ||
- typeof form !== 'number') {
- return text;
+ if (typeof input !== 'object' || typeof number !== 'number' || typeof form !== 'number') {
+ return input;
}
- var fragments = text.split(';');
+ if (typeof input === 'string') {
+ return input;
+ }
// Perform plural form or return original text
- return i18n.pluralForms[form].apply(null, [number].concat(fragments)) || text;
+ return i18n.pluralForms[form].apply(null, [number].concat(input));
}
;
-
// Fetch the localized version of the string
if (i18n.locale.strings && i18n.locale.strings[language]) {
str = i18n.locale.strings[language][message];

0 comments on commit 356dcb5

Please sign in to comment.