Skip to main content
Topic: Translate this (Read 1616 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Translate this

I was trying to think of how to make it so that you can navigate around a forum and make strings translatable or at least view what the key of the language string is. Thinking of an easy way to do that I decided that I could just wrap the string in a span with a class "string" (or something) and then a data-lang-key="[lang key]". The result would be something like <span class="lang_string" data-lang-key="board_name">Board name</span>. Then all of the $txt uses would be changed to txt('key'). Using some JS, you could click (or right click) and then it would take you to the language editor and let you change the language strings.

Code: [Select]
function ($key, $do_wrapper = false)
{
    global $txt;

    return !$do_wrapper ? $txt[$key] : '<span class="lang_string" data-lang-key="' . $key . '">' . $txt[$key] . '</span>';
}

Anywhere this wouldn't work?

Re: Translate this

Reply #1

Cool idea ...
QuoteAnywhere this wouldn't work?
no major things come to mind, I'm sure that there could be a couple of odd spots where the key is built (extra logic), but thats no reason to not do this.

Re: Translate this

Reply #2

Interesting! :D
Bugs creator.
Features destroyer.
Template killer.

Re: Translate this

Reply #3

Had a similar idea after I coded my language editor. Coincidentally, recently got around to trying a very rough mock-up with a project I'm working on. There are limitations such as when text strings only appear on conditions and when they are inside stuff where you can't have the necessary HTML like submit button values, select box options, page titles and similar stuff. Still it's a pleasant experience for a translator when they see the context of the stuff that they are translating. If you would like to have a taste of it, it's here: bluedream.info/demo/misao Don't worry about breaking it and play with it to your heart's content!

Re: Translate this

Reply #4

Awesome [SiNaN] ! :D
Bugs creator.
Features destroyer.
Template killer.