Hi,
when displaying messages containing usernames in Javascript code, one needs to pass the gender of the given user. This usually means sending a userinfo API query, possibly sending it to a different domain and forcing a DNS lookup (since the given user sometimes resides on another wiki, e.g. in the case of images transcluded from a repository such as Commons), which can be quite slow. The time and bandwidth spent on this is often wasted, since not all languages have the concept of gender; for such languages, the API request should be omitted.
So, - how can I tell from Javascript code whether the current language supports genders? (I guess relying on that is not 100% failsafe, since even if it doesn't, a fallback language still might, but that sounds unlikely enough to ignore.) - how can I tell whether a given message depends on the gender? I suppose I could grep for '{{gender', or use mw.language to parse it with all genders and check if the output differs, but both of those are ugly and fragile. Is there a better option?
thanks Gergő
Depending on your context, adding an explicit 'mediawiki.user' resource loader module dependency might save a later api call to server for gender. That RL module will set the gender at mw.user and you can access by mw.user.options.get( 'gender' )[1]
[1] https://github.com/wikimedia/mediawiki-core/blob/master/includes/resourceloa...
Thanks Santhosh
On Sat, Apr 19, 2014 at 8:27 PM, Gergo Tisza gtisza@wikimedia.org wrote:
Hi,
when displaying messages containing usernames in Javascript code, one needs to pass the gender of the given user. This usually means sending a userinfo API query, possibly sending it to a different domain and forcing a DNS lookup (since the given user sometimes resides on another wiki, e.g. in the case of images transcluded from a repository such as Commons), which can be quite slow. The time and bandwidth spent on this is often wasted, since not all languages have the concept of gender; for such languages, the API request should be omitted.
So,
- how can I tell from Javascript code whether the current language supports
genders? (I guess relying on that is not 100% failsafe, since even if it doesn't, a fallback language still might, but that sounds unlikely enough to ignore.)
- how can I tell whether a given message depends on the gender? I suppose I
could grep for '{{gender', or use mw.language to parse it with all genders and check if the output differs, but both of those are ugly and fragile. Is there a better option?
Do you need the gender of the current user, or of another user?
If you need the gender of the current user, all you need to do is depend on mediawiki.user and mediawiki.jqueryMsg, then just pass mw.user (the user object) as the parameter to {{GENDER:$1|...}}. If you need the gender of a different user, I'm not sure that's even available.
Roan
On Sat, Apr 19, 2014 at 9:24 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
Do you need the gender of the current user, or of another user?
If you need the gender of the current user, all you need to do is depend on mediawiki.user and mediawiki.jqueryMsg, then just pass mw.user (the user object) as the parameter to {{GENDER:$1|...}}. If you need the gender of a different user, I'm not sure that's even available.
I need the gender of a different user (the one who uploaded a given image - not even necessarily a user on the same wiki). It is available via the users API, [1] what I need to know is whether it is necessary.
I wouldn't do it per language, even though there are languages that hardly ever need gender, such as Hungarian ;)
Perhaps it could be done per message - to have a function somewhere in jqueryMsg that quickly checks whether the parsed message would actually be different for different genders, and if it would be the same then not to do the API call. I guess that a simple regex that checks whether a message has a GENDER clause with more than one parameter is enough, but I might be wrong.
-- Amir Elisha Aharoni · אָמִיר אֱלִישָׁע אַהֲרוֹנִי http://aharoni.wordpress.com “We're living in pieces, I want to live in peace.” – T. Moore
2014-04-20 7:28 GMT+03:00 Gergo Tisza gtisza@wikimedia.org:
On Sat, Apr 19, 2014 at 9:24 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
Do you need the gender of the current user, or of another user?
If you need the gender of the current user, all you need to do is depend on mediawiki.user and mediawiki.jqueryMsg, then just pass mw.user (the user object) as the parameter to {{GENDER:$1|...}}. If you need the gender of a different user, I'm not sure that's even available.
I need the gender of a different user (the one who uploaded a given image
- not even necessarily a user on the same wiki). It is available via the
users API, [1] what I need to know is whether it is necessary.
[1] https://www.mediawiki.org/wiki/API:Users
Mediawiki-i18n mailing list Mediawiki-i18n@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-i18n
On Sun, Apr 20, 2014 at 02:35:49PM +0300, Amir E. Aharoni wrote:
I wouldn't do it per language, even though there are languages that hardly ever need gender, such as Hungarian ;)
Perhaps it could be done per message - to have a function somewhere in jqueryMsg that quickly checks whether the parsed message would actually be different for different genders, and if it would be the same then not to do the API call. I guess that a simple regex that checks whether a message has a GENDER clause with more than one parameter is enough, but I might be wrong.
I think this is tgr's suggestion about parsing it with all possible genders and then comparing. Doing it by parsing the message itself looking for different GENDER parameters strikes me as being not terribly future-proof...
On Sat, Apr 19, 2014 at 9:24 PM, Roan Kattouw roan.kattouw@gmail.com wrote:
Do you need the gender of the current user, or of another user? If you need the gender of the current user, all you need to do is depend on mediawiki.user and mediawiki.jqueryMsg, then just pass mw.user (the user object) as the parameter to {{GENDER:$1|...}}. If you need the gender of a different user, I'm not sure that's even available. "Gergo Tisza" gtisza@wikimedia.org writes:
I need the gender of a different user (the one who uploaded a given image - not even necessarily a user on the same wiki). It is available via the users API, [1] what I need to know is whether it is necessary.
Maybe not a good solution but a working one: Just assume the user did not reveal their gender: use the "gender unknown" message variant and avoid gender processing. Of course, you could make this behavior depend on a sort of "misermode" switch.
Purodha
mediawiki-i18n@lists.wikimedia.org