i18n and Numerus

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!

i18n and Numerus

Postby cmb » Sun Apr 15, 2012 11:31 pm

Hello Developers,

just some hours ago I've published a plugin with an awkward bug: it might print "1 votes" :oops: As it might be obvious for most developers to avoid this bug, it might be not so obvious that in many languages there's more than singular and plural: the paucal! (Honestly I'm not sure, if it's called this way in any language, but the principle might be the same -- please correct me, if I'm wrong)

This brought me to the following solution. Wherever a language specific string, depending on the numerus, might be used, it could be returned by the following function:
Code: Select all
/**
 * Returns $tx in its correct numerus according to $count.
 *
 * @param string $plugin  The name of the plugin.
 * @param string $tx  The base name of the language string.
 * @param int $count  The item's count.
 * @return string
 */
function XYZ_numerus($plugin, $tx, $count) {
    global $plugin_tx;

    $ptx = $plugin_tx[$plugin];
    $limit = isset($ptx['paucal_limit']) ? $ptx['paucal_limit'] : 4;
    $singular = isset($ptx[$tx.'_singular']) ? $ptx[$tx.'_singular'] : $ptx[$tx];
    $paucal = isset($ptx[$tx.'_paucal']) ? $ptx[$tx.'_paucal']
        : ($ptx[$tx.'_plural'] ? $ptx[$tx.'_plural'] : $ptx[$tx]);
    $plural = isset($ptx[$tx.'_plural']) ? $ptx[$tx.'_plural'] : $ptx[$tx];
    if ($count > $limit || $count == 0) {
    return $plural;
    } elseif ($count > 1) {
    return $paucal;
    } else {
    return $singular;
    }
}
 

It's important, that the XYZ will be replaced by the plugin's name (or some abbreviation), or the routine might be offered by some general utility plugin/addon. The benefits of using this routine: if no singular/paucal/plural is defined, a somewhat reasonable default will be used. So an english speaking developer might ignore the paucal (and even singular/plural forms) -- but the translator is able to introduce the paucal (singular/plural) afterwards. Additionally it's possible to set the upper limit for the paucal in the language file. The drawbacks: a somewhat slight decline of performance.

I'm very interested in your opinion about this function, and it's possible shortcommings (e.g. I'm not sure, if zero occurences use the plural form in all languages).

Christoph
Christoph M. Becker---Plugins for CMSimple_XH
cmb
 
Posts: 5484
Joined: Tue Jun 21, 2011 11:04 am
Location: Germany

Re: i18n and Numerus

Postby oldnema » Mon Apr 16, 2012 7:22 am

In the Czech language is as follows:
0 votes = 0 hlasů
1 vote = 1 hlas
2,3,4 votes = 2,3,4 hlasy
5 (or more) votes = 5 (a více) hlasů
Nobody knows how much time he has left ...
http://oldnema.compsys.cz/en/?Demo_templates
oldnema
 
Posts: 149
Joined: Wed Jan 21, 2009 5:15 pm
Location: Czech Republic

Re: i18n and Numerus

Postby Tata » Mon Apr 16, 2012 9:55 am

Exactly!
I have forgotten about "0"
It shall sound:
0 votes = 0 hlasov
1 vote = 1 hlas
2,3,4 = 2,3,4 hlasy
5+ = 5+ hlasov
Image
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.
Tata
 
Posts: 1438
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia

Re: i18n and Numerus

Postby Gert » Tue Apr 17, 2012 5:14 pm

Hello,

simply solution for all languages:

votes: 0 (1, 2, 3, ... 728) ;)

I have made it this way in Comment_XH (Kommentare: 0): http://www.ge-webdesign.de/plugindemo/?Plugin_Demo_Seiten:Comments_XH

Gert
Gert Ebersbach | CMSimple | Templates - Plugins - Services
Gert
 
Posts: 4546
Joined: Fri May 30, 2008 4:53 pm
Location: Berlin

Re: i18n and Numerus

Postby cmb » Tue Apr 17, 2012 6:04 pm

Hi Gert,

indeed, that would work in this case too! But the wording might be a bit clumsy for other cases.

BTW: I had forgotten to include the plural forms for Poll_XH again. At least for now you might use Gert's suggestion.

Christoph
Christoph M. Becker---Plugins for CMSimple_XH
cmb
 
Posts: 5484
Joined: Tue Jun 21, 2011 11:04 am
Location: Germany

Re: i18n and Numerus

Postby Tata » Tue Apr 17, 2012 6:10 pm

You are right, Gert about this one or similar expressions. But as long as there is some proper sentence using the variable in its content, e.g.:
"You may upload max. %s $images".
This fork won't work. It is only the question if the page shall "communicate" with the visitor (Saying him "You have still 10 days remaining") or she shall only show him labels and announcements ("Remaining days: 10").
If an expression like - Votes: 0 - is gramarly correct, it is again a gramar-phylosofic question. My wife (Slovak teacher) says it is wrong :shock: But she can't work with computer :lol:
Image
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.
Tata
 
Posts: 1438
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia


Return to Open Development

Who is online

Users browsing this forum: No registered users and 0 guests

cron