Translate JS Messages

M

Marcos

I need to translate the messages of mine scripts, as I can make
professionally this working with the pair php and javascript?

Thank`s
 
E

Evertjan.

Marcos wrote on 01 mrt 2005 in comp.lang.javascript:
I need to translate the messages of mine scripts, as I can make
professionally this working with the pair php and javascript?

Translate as in:

alert('Hi folks')

to

alert('Bonjour a tous')

?

If so what is your question?
 
M

Marcos

My question is, how do it with php and javascript, but the website it goes
to have many languages.

Thank's.

Marcos
 
D

David Dorward

Marcos said:
My question is, how do it with php and javascript, but the website it goes
to have many languages.

The same way you translate the rest of your content - presumably through
gettext.
 
G

Grant Wagner

Marcos said:
My question is, how do it with php and javascript, but the website it
goes to have many languages.

Thank's.

Marcos

In index.html.en you'd have:

<script type="text/javascript">
var localizationResources = [ 'Hi folks', 'whatever', 'whatever' ];
</script>

In index.html.fr you'd have:

<script type="text/javascript">
var localizationResources = [ 'Bonjour a tous, 'whatever', 'whatever' ];
</script>

In all files you'd have:

<script type="text/javascript">
function greeting()
{
alert(localizationResources[0]);
}
// ...
</script>

The other thing to do is to use PHP to determine the language and
dynamically write the correct client-side script:

<?php
// figure out what language the user is using
if (they are using french) {
$greeting = "french";
} else if (they are using english) {
$greeting = "english";
}
<script type="text/javascript">
alert('<?php echo $greeting ?>');
</script>

I'd prefer the second method because then you don't need to dump all the
localization resources to the client, you only produce the localization
values you need.
 
M

Marcos

You they had helped very!

Thank's.

Em Tue, 01 Mar 2005 20:01:37 GMT, Grant Wagner
Marcos said:
My question is, how do it with php and javascript, but the website it
goes to have many languages.

Thank's.

Marcos

In index.html.en you'd have:

<script type="text/javascript">
var localizationResources = [ 'Hi folks', 'whatever', 'whatever' ];
</script>

In index.html.fr you'd have:

<script type="text/javascript">
var localizationResources = [ 'Bonjour a tous, 'whatever', 'whatever' ];
</script>

In all files you'd have:

<script type="text/javascript">
function greeting()
{
alert(localizationResources[0]);
}
// ...
</script>

The other thing to do is to use PHP to determine the language and
dynamically write the correct client-side script:

<?php
// figure out what language the user is using
if (they are using french) {
$greeting = "french";
} else if (they are using english) {
$greeting = "english";
}
<script type="text/javascript">
alert('<?php echo $greeting ?>');
</script>

I'd prefer the second method because then you don't need to dump all the
localization resources to the client, you only produce the localization
values you need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top