coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

Manually load 'string' #18

Closed Toverbal closed 12 years ago

Toverbal commented 12 years ago

I guess this is more a feature request, but I'll post it here anyway :). I need to localize a web page, but it does not only contain html elements that need translation, there are also some dynamic div's, alerts and prompts. From what I have read it is not possible to do something like loading the localization normally (which localizes all elements on the page) and then after they are loaded use e.g. alert($.localize.load("msg_are_you_sure")) , which will use the last loaded localization. I figured I could use hidden inputs to store all these messages, but the approach I suggested might be more comfortable.

I'm sorry if I overlooked an existing feature here...

Toverbal commented 12 years ago

It could also come in handy for formatting strings. Often a localization string contains something like 'You currently have %s items in your basket'.

coderifous commented 12 years ago

Hi Jori - assuming the default callback is used, you can access all of the language data via $.localize.data. You can use that to access localized strings at runtime.

Toverbal commented 12 years ago

Thanks for the quick response and that's just perfect for my situation, so thanks!

coderifous commented 12 years ago

:thumbsup:

costales commented 9 years ago

Hi @coderifous. How can I do that if the translations file are in a subdirectory?

This is not working by the "/":

<script>
    $("[data-localize]").localize("locales/messages", { language: "es" });
    console.log($.localize.data.locales/messages.search);
</script>

In the root path is working (But I'd like the messages in a subdirectory):

<script>
    $("[data-localize]").localize("messages", { language: "es" });
    console.log($.localize.data.messages.search);
</script>

Or if I want to translate a string with spaces, like "My string"?

{
  "My string": "Mi señal"
}

Thanks in advance and for your great plugin!

costales commented 9 years ago

I'm so sorry :) I found it:

    console.log($.localize.data["locales/messages"]["My String"]);

A hug and thanks again :)

RobertKolman commented 7 years ago

Thanks a lot. I could not find it more than an hour. You are my hero :D