views:

29

answers:

1

Hello. Suppose there is a website that supports multiple languages:

  • cn.mydomain.com or mydomain.com/cn or mydomain.cn
  • en.mydomain.com or mydomain.com/en or mydomain.com
  • fr.mydomain.com or mydomain.com/fr or mydomain.fr

I want to write a GreaseMonkey script that has variables assigned different strings/values according to the address the user is loading the page from. How do you do that? Thanks

EDIT: I realize I can just use JavaScript to get the address. Does GreaseMonkey itself support this kind of function?

+1  A: 

Does GreaseMonkey itself support this kind of function?

No it does not.

Erik Vold
It seems to me that it should be possible to write a script that would take the url, and document data into account and figure out what language was used on the page visited. Then if they have a cache of translations of their text (an object storing the text displayed to the user in all langs supported), then they could choose the appropriate one.Or you could use Google Translate to detect and/or translate your text to w/e, this would mean a large number of xhr requests are made so I do not recommend it.
Erik Vold
Thanks for the info. What is the language cache you refer to? I'm not familiar with this. Basically I'm trying to detect the language currently displayed to the user so my scripts can display accordingly. Your tip of examining the url and document data should be sufficient, no?
Dan7
"Thanks for the info. What is the language cache you refer to?" I simply meant it is an object storing the text displayed to the user in all langs supported.
Erik Vold
"Your tip of examining the url and document data should be sufficient, no?" Yes this should work, and I believe these are the only options available.
Erik Vold