Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problems with l10ns that rely on 'labeln' with n >= 2 #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions jquery.countdown-hr.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
/* http://keith-wood.name/countdown.html
* Croatian Latin initialisation for the jQuery countdown extension
* Written by Dejan Broz [email protected] (2011) */
/**
* http://keith-wood.name/countdown.html
* Croatian l10n for the jQuery countdown plugin
* Written by Dejan Broz [email protected] (2011)
* Improved by zytzagoo (2014)
*/
(function($) {
var PLURAL_FORM_REST = 0;
var PLURAL_FORM_SINGLE = 1;
var PLURAL_FORM_PAUCAL = 2;
var determine_plural_form = function(amount) {
amount = parseInt(amount, 10);
// assume default plural (most common case)
var plural_form = PLURAL_FORM_REST;
if (amount % 10 === 1 && amount % 100 !== 11) {
// singles (/.*1$/ && ! /.*11$/)
plural_form = PLURAL_FORM_SINGLE;
}
if ((amount % 10 >= 2) && (amount % 10 <= 4) && (amount % 100 < 10 || amount % 100 >= 20)) {
// paucals (/.*[234]$/ && ! /.*1[234]$/
plural_form = PLURAL_FORM_PAUCAL;
}
return plural_form;
};
$.countdown.regionalOptions['hr'] = {
// plurals
labels: ['Godina', 'Mjeseci', 'Tjedana', 'Dana', 'Sati', 'Minuta', 'Sekundi'],
labels1: ['Godina', 'Mjesec', 'Tjedan', 'Dan', 'Sat', 'Minuta', 'Sekunda'],
labels2: ['Godine', 'Mjeseca', 'Tjedna', 'Dana', 'Sata', 'Minute', 'Sekunde'],
// singles
labels1: ['Godina', 'Mjesec', 'Tjedan', 'Dan', 'Sat', 'Minutu', 'Sekundu'],
// paucals
labels2: ['Godine', 'Mjeseca', 'Tjedana', 'Dana', 'Sata', 'Minute', 'Sekunde'],
compactLabels: ['g', 'm', 't', 'd'],
whichLabels: function(amount) {
return (amount == 1 ? 1 : (amount >= 2 && amount <= 4 ? 2 : 0));
whichLabels: function(amount){
return determine_plural_form(amount);
},
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
timeSeparator: ':', isRTL: false};
Expand Down
38 changes: 18 additions & 20 deletions jquery.countdown.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* http://keith-wood.name/countdown.html
Countdown for jQuery v2.0.0.
Countdown for jQuery v2.0.1.
Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
Please attribute the author if you use it. */

(function($) { // Hide scope, no $ conflict
Expand All @@ -26,7 +26,7 @@
@augments JQPlugin
@example $(selector).countdown({until: +300}) */
$.JQPlugin.createPlugin({

/** The name of the plugin. */
name: pluginName,

Expand All @@ -38,7 +38,7 @@
Triggered when the countdown is initialised.
@callback serverSyncCallback
@return {Date} The current date/time on the server as expressed in the local timezone. */

/** Countdown tick callback.
Triggered on every <code>tickInterval</code> ticks of the countdown.
@callback tickCallback
Expand All @@ -51,7 +51,7 @@
@callback whichLabelsCallback
@param num {number} The current period value.
@return {number} The suffix for the label set to use. */

/** Default settings for the plugin.
@property until {Date|number|string} The date/time to count down to, or number of seconds
offset from now, or string of amounts and units for offset(s) from now:
Expand Down Expand Up @@ -146,7 +146,7 @@
isRTL: false
}
},

/** Names of getter methods - those that can't be chained. */
_getters: ['getTimes'],

Expand Down Expand Up @@ -208,7 +208,7 @@
requestAnimationFrame(timerCallBack);
}
},

/** Convert a date/time to UTC.
@param tz {number} The hour or minute offset from GMT, e.g. +9, -360.
@param year {Date|number} the date/time in that timezone or the year in that timezone.
Expand Down Expand Up @@ -357,22 +357,20 @@
@param base {object} The options to be updated.
@param options {object} The new option values. */
_resetExtraLabels: function(base, options) {
var changingLabels = false;
for (var n in options) {
if (n != 'whichLabels' && n.match(/[Ll]abels/)) {
changingLabels = true;
break;
if (n.match(/[Ll]abels[02-9]|compactLabels1/)) {
base[n] = options[n];
}
}
if (changingLabels) {
for (var n in base) { // Remove custom numbered labels
if (n.match(/[Ll]abels[02-9]|compactLabels1/)) {
for (var n in base) {
if (n.match(/[Ll]abels[02-9]|compactLabels1/)) {
if(typeof options[n] === 'undefined') {
base[n] = null;
}
}
}
},

/** Calculate internal settings for an instance.
@private
@param elem {jQuery} The containing division.
Expand Down Expand Up @@ -477,7 +475,7 @@
inst[inst._since ? '_since' : '_until'] =
this._determineTime(sign + inst._periods[0] + 'y' +
sign + inst._periods[1] + 'o' + sign + inst._periods[2] + 'w' +
sign + inst._periods[3] + 'd' + sign + inst._periods[4] + 'h' +
sign + inst._periods[3] + 'd' + sign + inst._periods[4] + 'h' +
sign + inst._periods[5] + 'm' + sign + inst._periods[6] + 's');
this._addElem(elem);
}
Expand Down Expand Up @@ -529,7 +527,7 @@
case 'd': day += parseInt(matches[1], 10); break;
case 'w': day += parseInt(matches[1], 10) * 7; break;
case 'o':
month += parseInt(matches[1], 10);
month += parseInt(matches[1], 10);
day = Math.min(day, self._getDaysInMonth(year, month));
break;
case 'y':
Expand Down Expand Up @@ -620,8 +618,8 @@
inst.options.compact, inst.options.significant, showSignificant) :
((inst.options.compact ? // Compact version
'<span class="' + this._rowClass + ' ' + this._amountClass +
(inst._hold ? ' ' + this._holdingClass : '') + '">' +
showCompact(Y) + showCompact(O) + showCompact(W) + showCompact(D) +
(inst._hold ? ' ' + this._holdingClass : '') + '">' +
showCompact(Y) + showCompact(O) + showCompact(W) + showCompact(D) +
(show[H] ? this._minDigits(inst, inst._periods[H], 2) : '') +
(show[M] ? (show[H] ? inst.options.timeSeparator : '') +
this._minDigits(inst, inst._periods[M], 2) : '') +
Expand Down Expand Up @@ -750,7 +748,7 @@
show[S] = (format.match('s') ? '?' : (format.match('S') ? '!' : null));
return show;
},

/** Calculate the requested periods between now and the target time.
@private
@param inst {object} The current settings for this instance.
Expand Down
Loading