[Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Yuri Astrakhan
Hi, I need to use the localization framework - wfMessage() to translate my
own custom messages. I have a message dictionary in the form of
{languageCode = message, ...}, and looking for a way to inject those
messages into the message cache. The actual messages dictionary is stored
as a custom setting as part of a json blob, and cannot be added to the
regular $message['xx'] = '...'; for  translatewiki.  Thanks!

Usage scenario:

// Array is generated from an external source and will look like this:
$messageMap = array('en'='aaa', 'fr'='b {{SITENAME}} b', ...);

// Some magic method to add the entire message map into message cache
messageCache-Add('custom-key1', $messageMap);

// Process message
// Note that in case 'fr' is not defined, it should fallback using default
resolution rules.
$result = wfMessage('custom-key1')-inLanguage('fr')-text();
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Matthew Walker

  I have a message dictionary in the form of
 {languageCode = message, ...}, and looking for a way to inject those
 messages into the message cache.


My immediate reaction was to suggest that you create wikipages of all the
messages. But I'm guessing this is for Zero and you can't have those
messages being changed?

Can you not just parse the messages yourself? About all that wfMessage
beyond the parser is giving you is the cache abstraction (which is mostly
overhead in your case, it sounds like you already have all the strings in
memory.)

~Matt Walker
Wikimedia Foundation
Fundraising Technology Team


On Mon, Apr 8, 2013 at 12:05 PM, Yuri Astrakhan yastrak...@wikimedia.orgwrote:

 Hi, I need to use the localization framework - wfMessage() to translate my
 own custom messages. I have a message dictionary in the form of
 {languageCode = message, ...}, and looking for a way to inject those
 messages into the message cache. The actual messages dictionary is stored
 as a custom setting as part of a json blob, and cannot be added to the
 regular $message['xx'] = '...'; for  translatewiki.  Thanks!

 Usage scenario:

 // Array is generated from an external source and will look like this:
 $messageMap = array('en'='aaa', 'fr'='b {{SITENAME}} b', ...);

 // Some magic method to add the entire message map into message cache
 messageCache-Add('custom-key1', $messageMap);

 // Process message
 // Note that in case 'fr' is not defined, it should fallback using default
 resolution rules.
 $result = wfMessage('custom-key1')-inLanguage('fr')-text();
 ___
 Wikitech-l mailing list
 Wikitech-l@lists.wikimedia.org
 https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Chad
On Mon, Apr 8, 2013 at 3:05 PM, Yuri Astrakhan yastrak...@wikimedia.org wrote:
 // Some magic method to add the entire message map into message cache
 messageCache-Add('custom-key1', $messageMap);


So, we used to have a $messagecache-add(), but it was removed
after a very very long deprecation.

-Chad

___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Yuri Astrakhan
 So, we used to have a $messagecache-add(), but it was removed
 after a very very long deprecation.


Just when  I was about to use it :) I basically look for this functionality:

* Figure out which localized string to use for language X, in case there is
no message in X. Something like use Russian if Belarusian message is not
available. I remember this was present in pywiki framework, and suspect
mediawiki has it somewhere.

* Expand {{templates}}/PLURAL/GENDER/...
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Matthew Flaschen
On 04/08/2013 03:21 PM, Yuri Astrakhan wrote:
 * Figure out which localized string to use for language X, in case there is
 no message in X. Something like use Russian if Belarusian message is not
 available. I remember this was present in pywiki framework, and suspect
 mediawiki has it somewhere.

That's correct.  For instance, Mirandese (mwl) falls back to Portugese (pt).

Matt Flaschen

___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Ryan Kaldari
Take a look at the CentralNotice extension. It provides it's own 
interface for adding custom translatable messages. There might be some 
code there that is useful to you.


Ryan Kaldari

On 4/8/13 12:05 PM, Yuri Astrakhan wrote:

Hi, I need to use the localization framework - wfMessage() to translate my
own custom messages. I have a message dictionary in the form of
{languageCode = message, ...}, and looking for a way to inject those
messages into the message cache. The actual messages dictionary is stored
as a custom setting as part of a json blob, and cannot be added to the
regular $message['xx'] = '...'; for  translatewiki.  Thanks!

Usage scenario:

// Array is generated from an external source and will look like this:
$messageMap = array('en'='aaa', 'fr'='b {{SITENAME}} b', ...);

// Some magic method to add the entire message map into message cache
messageCache-Add('custom-key1', $messageMap);

// Process message
// Note that in case 'fr' is not defined, it should fallback using default
resolution rules.
$result = wfMessage('custom-key1')-inLanguage('fr')-text();
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l



___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Adding messages to cache for wfMessage() at runtime

2013-04-08 Thread Matthew Walker

 Take a look at the CentralNotice extension. It provides it's own interface
 for adding custom translatable messages. There might be some code there
 that is useful to you.


Sadly unlikely; CN adds messages by creating WikiPages.

~Matt Walker
Wikimedia Foundation
Fundraising Technology Team
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l