blocks
2 weeks ago
cleditor
2 weeks ago
codemirror
2 weeks ago
dfv
2 weeks ago
marionette
2 weeks ago
qtip
2 weeks ago
selectWoo
2 weeks ago
sprintf
2 weeks ago
timepicker
2 weeks ago
handlebars.js
2 weeks ago
jquery.pods.js
2 weeks ago
jquery.pods.upgrade.js
2 weeks ago
pods-i18n.js
2 weeks ago
pods-link-picker.js
2 weeks ago
qtip.js
2 weeks ago
pods-i18n.js
63 lines
| 1 | /*global podsLocalizedStrings, sprintf */ |
| 2 | 'use strict'; |
| 3 | var PodsI18n = (function () { |
| 4 | |
| 5 | /** |
| 6 | * Only visible to the closure, not exposed externally. |
| 7 | * @param {string} str |
| 8 | * @returns {string} |
| 9 | */ |
| 10 | var translateString = function ( str ) { |
| 11 | var translated = str, ref; |
| 12 | |
| 13 | if ( typeof podsLocalizedStrings !== 'undefined' ) { |
| 14 | |
| 15 | /** |
| 16 | * Converts string into reference object variable |
| 17 | * Uses the same logic as PHP to create the same references |
| 18 | */ |
| 19 | ref = '__' + str; |
| 20 | |
| 21 | if ( typeof podsLocalizedStrings[ ref ] !== 'undefined' ) { |
| 22 | translated = podsLocalizedStrings[ ref ]; |
| 23 | } |
| 24 | else if ( podsLocalizedStrings.debug ) { |
| 25 | console.log( 'PodsI18n: String not found "' + str + '" (reference used: "' + ref + '")' ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | return translated; |
| 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * The returned object, this is what we'll expose to the outside world |
| 34 | */ |
| 35 | return { |
| 36 | /** |
| 37 | * @param {string} str |
| 38 | * @returns {string} |
| 39 | */ |
| 40 | __: function ( str ) { |
| 41 | return translateString( str ); |
| 42 | }, |
| 43 | |
| 44 | /** |
| 45 | * @param {string} single |
| 46 | * @param {string} plural |
| 47 | * @param {number} number |
| 48 | * |
| 49 | * @returns {string} |
| 50 | */ |
| 51 | _n: function ( single, plural, number ) { |
| 52 | |
| 53 | // Unary + will implicitly cast to numeric |
| 54 | if ( +number === 1 ) { |
| 55 | return translateString( single ); |
| 56 | } |
| 57 | else { |
| 58 | return translateString( plural ); |
| 59 | } |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | }()); |