Dropplets Localization
In order to do this server-side, we'd need to take out all Dropplets hard-coded strings and replace them with a function, like so:
<a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
Powered by Dropplets
</a>
... would become ...
<a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
<?php echo international("Powered by Dropplets"); ?>
</a>
The international function would look like:
function international($key) {
if(in_array($key, $translations)) {
return $translations[$key];
}
return $key;
}
This way, should a translation not exist, the site will automatically default back to English.
couldn't you just use gettext strings? (e.g. __(), _n, _e)
That sounds like a much better idea. :+1:
I didn't even know such a thing existed, my apologies.
I only know i18n in a WordPress context, but the functions themselves are generic php functions. The basic idea is you wrap your test strings in a php function like the ones I've listed, so:
<a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
<?php _e( 'Powered by Dropplets', 'dropplets' ); ?>
</a>
Then when you run your code through gettext (e.g. with a translation program like Poedit, although you can do this with a php function as well), you tell it to look for _e and __ and _n and any other localization functions you're using and it will pull out those text strings that are wrapped in those functions and allow you to generate .po/.mo language files which can be used for translating the program.
There may be more that I'm not thinking of in terms of calling and initializing the language files because I haven't dug deep into how WordPress uses the language files once they are there, but the first step would be just getting it ready for gettext.
Note: your method isn't far off and could actually work if the function international was added to Poedit when you were creating the .pot file, but I don't think it would be strictly necessary unless there were things you were doing in the function that weren't being done otherwise (say stripping out html entities or something).