Support for other languages?

in
Subscribe to Support for other languages? 6 posts, 3 voices



Vess Scriptwright

Any chance of implementing support for other languages? I don't really care for the language of the displayed information - but I'd like the script to work on game servers other than ogame.fr. There is a similar function in NeoGame - but it, too, does not support all the game servers I'm interested in.

 
jeanc Script's Author

Possible if I have enough information, it shouldn't be too difficult.
I check

 
jeanc Script's Author

Ok, I checked, I need very few information to support other languages :
1. Name of the server
2. Exact string for mouseover on a mission, on transport, an example in french :
'Transporter :
Métal: xxx.xxx.xxx
Cristal: xxx.xxx.xxx
Deutérium: xxx.xxx.xxx'

3. The exact string of the Events/Mission block (in french "Evènements"), before the missions and after the server's time.

Give me your msn/email if you need any info

 
Oliver Jensen Scriptwright
MozillaX11

Heya Vess

As it happens, I wrote a similar albeit much simpler script which supports all languages:
http://userscripts.org/scripts/show/53926

jeanc: In order to get the strings for Metal, Crystal, etc. just use whatever strings the server uses in the header. The code I use is:

var mstring = document.getElementById('resources').getElementsByTagName('tr')[1].getElementsByTagName('font')[0].innerHTML;
var cstring = document.getElementById('resources').getElementsByTagName('tr')[1].getElementsByTagName('font')[1].innerHTML;
var dstring = document.getElementById('resources').getElementsByTagName('tr')[1].getElementsByTagName('font')[2].innerHTML;

Also, you don't need those strings. You'll notice that you can get all the info you need from the 'title' attribute of the 5th anchor in every other class 'flight'. Here's my code to get the info:


var flights = document.getElementsByClassName('flight');
var info = new Object;
for (var i=1; i < flights.length; i=i+2)
{
var title = flights[i].getElementsByTagName('a')[5].title;
var elements = title.split(": ");
var type = elements[0];
var m = parseInt(elements[2].replace(/\./g,''));
var c = parseInt(elements[3].replace(/\./g,''));
var d = parseInt(elements[4].replace(/\./g,''));
if (!info[type])
info[type] = new Array(m,c,d);
else
{
info[type][0] = info[type][0] + m;
info[type][1] = info[type][1] + c;
info[type][2] = info[type][2] + d;
}
}

Note that my code just adds up all the totals for each type of mission - your script will need to do something more complicated. In any case though, you should be able to use that to make getting the information entirely language independent :)

Hope that helps!

 
jeanc Script's Author
FirefoxWindows

To be honest, I thought about that possibility this morning and I planed to do it soon :) You have just made me win some time!
Your message helped me also coz I didn't mind that getElementsByTagName was for all HTML element, I thought it was only used on document :) Getting resources of the planet is smth I did very quickly and then probably not using the best way, that method should match it better too :p
I will probably use your tips to improve my script ;)
But I am seeing a little pb in your script : what if you are only transporting crystal? I guess you have to check that possibility in your parsing code! (using the string you got just before)

 
Oliver Jensen Scriptwright
MozillaX11

Hi

It turns out the code I posted is horribly buggy - it's only reliable for transport fleets. Sorry! I'm working on fixing it, but for now, don't rely on it too much! I was just trying to make the point that it's probably better to navigate the dom than search for specific strings, as otherwise making it support other languages is a huge pain. Good luck!

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel