Osclass forums
Development => Plugins => Topic started by: Juan Ramón on September 06, 2011, 08:20:15 pm
-
i18n is an abbreviation for __internationalization__. You can get more information in the wikipedia. OSClass uses the GNU gettext lib... [more] (http://osclass.org/2011/09/06/translating-osclass-plugins-themes/)
-
when can we expect all plugins in new translating tool ?
-
that is an exatra work osclass developer, you should translate what you can use yourself. this is a piece of cake, write :D!
-
How can I make a plugin giving the option to an admin to translate the text, like in the listing section?.
I think it can be possible saving the text in the db, but I do not know how to change the text when the user selects their language.
any help is appreciated!
-
Each plugin should have translation files for each language and it is selected automatically (if available).
Regards
-
I think you did not understand my question.
For the static content I know I have to create the translation file, but I-m talking about dynamic content, like in the listing section.
every time you add a new language, in the listing section appears a new tab with the corresponding language where you can translate the content.
how can I replicate this? I have an idea how to show the form and the tabs, but once it's saved in the db,
I don't know if osclass has a specific function to select the current language, and show it.
-
Hi,
Here's an idea for you if you want to skip the whole vanilla mechanism for translations:
The main translation function __($key, $domain = 'core') in oc-includes/osclass/helpers/hTranslations.php returns a string using a filter "gettext", so you can intercept that string and change it according to your needs:
return osc_apply_filter('gettext', $string);
Then:
<?php
function my_plugin_translations($string) {
// if ( [$string belongs to my plugin] ) { [Find out current selected language -using osc_current_user_locale()- and retrieve the correct translation from the database] }
// return [translated string];
}
osc_add_filter('gettext', 'my_plugin_translations');
osc_add_filter('ngettext', 'my_plugin_translations');
?>
Regards
-
thnaks teseo
I'll try with your suggestion, if all is fine I'll provide an example to implement in other plugins.
best regards
-
implement in other plugins.
If you are trying to build a standard mechanism for plugin translations, I have to warn you that my idea is nothing but a hack that I proposed here thinking only of a single plugin using it. This method would work only after the normal translation process is performed, so it would add an overhead (more time).
I'd explore other angle: Given the fact that you would have to set some kind of interface to set translations anyway, why not store the results on a regular .po file and use something like this (https://github.com/phpmo/php.mo) to convert to .mo? ???
Regards
-
thanks again teseo,
that's a better way to solve this problem, I asked because in the listing section it's already implemented, so I imagined that could be some oficial function to do it, I'll look inside of the admin file to check how it's implemented there, if I don't get anything specific I will try with that php-mo function who is very easy to use!