Tokyoj

Topic: Replacing hard text with translation.ini strings

in a .js file there is hard coded text in a few instances where I want to replace the text with a string from translations.ini because I'm trying to manage all text from within translation.ini (later I'll be translating my site to offer language options.

Using these 3 examples:
1) var msg = "Your job has been posted.";
2) if(confirm('Delete this job ad?'))
3) $("a#new_location_label").html("Select an option");

I'm trying to replace the text with

1) var msg = "{$translations.notice.posted}";
2) if(confirm('{$translations.notice.delete}'))
3) $("a#new_location_label").html("{$translations.notice.select}");

but I'm making mistakes with the syntx when inserting
{$translations.notice.posted}
{$translations.notice.delete}
{$translations.notice.select}

Could someone show me how to do this in these examples?
Thank you.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

putypuruty

Re: Replacing hard text with translation.ini strings

Hi!

These strings are already in translation.ini, look towards the end of the file.

Tokyoj

Re: Replacing hard text with translation.ini strings

No...there not in the .ini file because they were added to the .js file recently and I translated them into English to post here.

But even if they were in there the question would still be the same...

How is the hard coded in the 3 examples replaced with strings in the translations.ini file?
Simply inputting...

{$translations.ABC.XYZ}

doesn't work.
Any ideas?

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

putypuruty

Re: Replacing hard text with translation.ini strings

Hi.

Sorry, it seems I was mistaken wink

Use this: Jobber.I18n.notice.posted, Jobber.I18n.notice.delete, Jobber.I18n.notice.select

For example:

Code:
if(confirm(Jobber.I18n.notice.delete))

Good luck!

Tokyoj

Re: Replacing hard text with translation.ini strings

Thanks but ???
I'm confused...how does that tell me how to insert a translation.ini string into
var msg = "Your job has been posted.";
to get
var msg = "{$translations.notice.posted}";

What is the code syntex?
I've tried...
var msg = "{$translations.notice.posted}";
var msg = '{$translations.notice.posted}';
var msg = "$translations.notice.posted";
var msg = "'$translations.notice.posted';
var msg = {$translations.notice.posted};
var msg = "{$translations.notice.posted}";
var msg = "$translations.notice.posted";
among many other combinations...

The goal is to get ALL text into the .ini file so translation can take place within 1 file.
Is it even possible to add translation.ini strings into .js files this way?

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: Replacing hard text with translation.ini strings

Javascript is a language that runs client-side, in contrary to PHP (which is run serverside). It shouldn't be approached as a template, but instead uses the I18n syntax shown above. In your case it should (probably) be:

var msg = Jobber.I18n.notice.posted;

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: Replacing hard text with translation.ini strings

I didn't realize I18n was the key. Makes sense. Thanks.

One last question...I searched online but couldn't find how to incorporate the string
Jobber.I18n.notice.posted
into 1 central language file such as translations.ini for Jobberbase but it seems getting 100% of the language into the .ini file is not going to be easy.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: Replacing hard text with translation.ini strings

I'm pretty sure it should grab the values already from the translations.ini, where 'notice' is the group and 'posted' the variable. Something like

[notice]
posted = "blabla text"

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: Replacing hard text with translation.ini strings

Yep. Tried that. Hmmm...What's the function of Jobber. at the beginning of the string?
I have a feeling that's where I'm messing up because I haven't renamed it correctly.
Now have....

$("a#other_location_label").html("Jobber.I18n.javascript.other");

and in translations.ini

[javascript]

other = "blabla"

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

putypuruty

Re: Replacing hard text with translation.ini strings

Hi.

You should have it like this:

Code:
$("a#other_location_label").html(Jobber.I18n.javascript.other);

Note that I've removed the double quotes because Jobber.I18n.javascript.other is already a JS variable. If you enclose it in double quotes, you are actually saying that you want to show the text Jobber.I18n.javascript.other inside that <a> tag, and not its contents (in my example blabla)

The above must work if you have

Code:
[javascript]
other = "blabla"

in translations.ini.

You can also look inside functions.js to see exactly how Jobber.I18n is used.

Tokyoj

Re: Replacing hard text with translation.ini strings

Found the problem....embarassing :\
I use an older Version and I18n was intro'd in V1.6...so obviously my version doesn't use those I18n for labels...I've added some significant customizations to my version so upgrading really isn't an option.

I've been reviewing how to use I18n but it seems like it's just too much work to integrate now.  Maybe I'm wrong...

Is there an easy to way to integrate I18n into an older version?

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)