Page MenuHomePhabricator

Add jQuery i18n to Pageviews Analysis
Closed, ResolvedPublic

Description

Some i18n messages in Pageviews Analysis are dynamically given values on the clientside. We need to use jQuery i18n to evaluate these messages.

Some messages that have JavaScript-supplied numerals that need {{PLURAL}} support:

Event Timeline

This one is tricky because the value to be passed into Intuition is dynamically generated on the clientside.

We're currently interpolating some messages into JavaScript, then replacing a string with the value we want:

i18nMessages.langviewsError = "#{$I18N->msg( 'langviews-error', array( 'variables' => array( 'i18n-arg' ) ) )}";

Then in our Javascript, we do i18nMessages.langeviewsError.replace('i18n-arg', 'the error message')

However if we use a magic word it's going to error out on the initial page load:

i18nMessages.numLanguages = "#{$I18N->msg( 'num-languages', array( 'variables' => array( 'i18n-arg' ), 'parsemag' => true ) )}";

because i18n-arg has not yet been replaced by the number fetched via AJAJ.

For this I'm not sure exactly what to do. I don't want to have to start up a new dictionary system just for the clientside, and using some sort of i18n JavaScript API to hit a backend service seems unnecessarily expensive for such a simple thing.

I'm guessing we'll just have to have two messages:

"num-languages": "$1 language",
"num-languages-plural": "$1 languages"

and then refer to whichever one as needed in the JavaScript. Far from ideal, but it'd work.

I'm guessing we'll just have to have two messages:

"num-languages": "$1 language",
"num-languages-plural": "$1 languages"

and then refer to whichever one as needed in the JavaScript. Far from ideal, but it'd work.

It won't work for languages using different plural forms than English: https://www.mediawiki.org/wiki/Localisation#Be_aware_of_PLURAL_use_on_all_numbers

Nemo_bis subscribed.

Far from ideal, but it'd work.

No. It would work for English and a minority of few languages. Else it would not work.

Ah, looking at this doc I see what you mean. I'm not sure of a solid workaround, then... :(

I guess I can explore a (very) lightweight API implementation for our purposes. It should go pretty fast, just will be a fair amount of work. The advantage here being we can still plug into Intuition and translatewiki, as opposed to a separate set of messages just for JavaScript.

Ah, looking at this doc I see what you mean. I'm not sure of a solid workaround, then... :(

I guess I can explore a (very) lightweight API implementation for our purposes. It should go pretty fast, just will be a fair amount of work. The advantage here being we can still plug into Intuition and translatewiki, as opposed to a separate set of messages just for JavaScript.

Thanks for looking int it!

I am not so much into the details of the implementations and handing parameters around, but generally, it seems preferable to have only one (or few) final implementations so as not to have a chance to let them get out of sync.

MusikAnimal renamed this task from [[Wikimedia:Pageviews-num-languages/en]] needs PLURAL to Add i18n JavaScript API to Pageviews Analysis.Apr 30 2016, 6:12 PM
MusikAnimal triaged this task as Medium priority.
MusikAnimal updated the task description. (Show Details)

What is the problem? Plural parsing in JavaScript is a solved problem and available in at least two ways: jquery.i18n and MediaWiki's jqueryMsg.

@Nikerabbit but do those hook up to translatewiki or do we need a new set of messages?

What do you mean with hook up? You get the strings in JSON files from translatewiki.net, and then you can use these libraries to parse them before display.

Got it! The issue here is we need to evaluate magic words, which I for some reason thought was limited to the Intuition library (PHP). I figured a clientside library would require separate messages to be inline with it's own parsing mechanism. Fortunately I am very wrong!! I should have simply asked someone who would be in the know :)

I think this will be really easy. Hope to get a fix out soon!

Many thanks

MusikAnimal renamed this task from Add i18n JavaScript API to Pageviews Analysis to Add jQuery i18n to Pageviews Analysis.May 3 2016, 6:12 PM
MusikAnimal updated the task description. (Show Details)
MusikAnimal claimed this task.

@Purodha Should be all set! Feel free to use {{PLURAL}} and {{GENDER}} for any messages that have parameters. I didn't add support for other less common magic words, but if something isn't working for you just let me know I can probably fix it.

Thanks for your hard work with the translations!

Also thank you @Nikerabbit for your keeping everything in sync! You both make this whole translation process seamless :)

Should be all set! Feel free to use {{PLURAL}} and {{GENDER}} for any messages that have parameters. I didn't add support for other less common magic words, but if something isn't working for you just let me know I can probably fix it.

This is a very late comment, I just stumbled upon this.

But I would like to ask you to please add {{PLURAL}} and {{GENDER}} to the relevant messages in the English original, so that it becomes absolutely clear to translators that they can use those in those messages. When I come across a message without them (especially when not translating MediaWiki itself), I just assume it won't work.

(Should I perhaps open a different task for this?)

But I would like to ask you to please add {{PLURAL}} and {{GENDER}} to the relevant messages in the English original, so that it becomes absolutely clear to translators that they can use those in those messages. When I come across a message without them (especially when not translating MediaWiki itself), I just assume it won't work.

(Should I perhaps open a different task for this?)

Yes, please open a new task :) But you are correct that we should be using the magic words where it makes sense to do so. I was new to all things i18n when I first started this project.

I know this is sad, but your comment also made me revisit @Purodha's profile, to discover that he has passed away :( Purodha did awesome work for Pageviews Analysis, and was the first person I added to the Phabricator project. I've been missing him ever since! I guess I just assumed that since July 2016 he had moved on to better things than helping me with translations, which I suppose in a way, he has. RIP!

Oh no, I didn't know that about Purodha. Very sad, and a big loss for Wikimedia. :-(