From 80e418ce5495f21b1c7acc75a7042690bc76949e Mon Sep 17 00:00:00 2001 From: zytzagoo Date: Wed, 30 Apr 2014 13:40:51 +0200 Subject: [PATCH] improved Croatian l10n in accordance with Croatian grammar --- jquery.countdown-hr.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/jquery.countdown-hr.js b/jquery.countdown-hr.js index 3758d1a..11413ae 100644 --- a/jquery.countdown-hr.js +++ b/jquery.countdown-hr.js @@ -1,14 +1,37 @@ -/* http://keith-wood.name/countdown.html - * Croatian Latin initialisation for the jQuery countdown extension - * Written by Dejan Broz info@hqfactory.com (2011) */ +/** +* http://keith-wood.name/countdown.html +* Croatian l10n for the jQuery countdown plugin +* Written by Dejan Broz info@hqfactory.com (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};