Loading


Advertisement:

Author Topic: How to translate OSClass plugins  (Read 9360 times)

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2384
How to translate OSClass plugins
« 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]

morvy

  • Full Member
  • ***
  • Posts: 103
  • always dissatisfied
Re: How to translate OSClass plugins
« Reply #1 on: July 20, 2012, 12:19:47 am »
when can we expect all plugins in new translating tool ?

safari45

  • Jr. Member
  • **
  • Posts: 73
  • Webmaster And Young Programmer
Re: How to translate OSClass plugins
« Reply #2 on: March 13, 2014, 12:24:09 pm »
that is an exatra work osclass developer, you should translate what you can use yourself. this is a piece of cake, write  :D!

gepd

  • Newbie
  • *
  • Posts: 16
Re: How to translate OSClass plugins
« Reply #3 on: October 07, 2014, 08:32:38 am »
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!
« Last Edit: October 07, 2014, 08:35:43 am by gepd »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1782
  • osclass.work
Re: How to translate OSClass plugins
« Reply #4 on: October 07, 2014, 11:20:28 am »
Each plugin should have translation files for each language and it is selected automatically (if available).

Regards
« Last Edit: October 07, 2014, 11:24:20 am by dev101 »

gepd

  • Newbie
  • *
  • Posts: 16
Re: How to translate OSClass plugins
« Reply #5 on: October 07, 2014, 10:13:59 pm »
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.

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: How to translate OSClass plugins
« Reply #6 on: October 07, 2014, 11:47:28 pm »
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:

Code: [Select]
return osc_apply_filter('gettext', $string);
Then:

Code: [Select]
<?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

gepd

  • Newbie
  • *
  • Posts: 16
Re: How to translate OSClass plugins
« Reply #7 on: October 08, 2014, 04:36:55 am »
thnaks teseo
I'll try with your suggestion, if all is fine I'll provide an example to implement in other plugins.

best regards

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: How to translate OSClass plugins
« Reply #8 on: October 08, 2014, 12:58:45 pm »
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 to convert to .mo? ???

Regards

gepd

  • Newbie
  • *
  • Posts: 16
Re: How to translate OSClass plugins
« Reply #9 on: October 09, 2014, 04:03:29 am »
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!