View Issue Details

IDProjectCategoryView StatusLast Update
12086Development [All Projects] Pluginspublic2017-06-18 11:33
ReporterDenisChenu Assigned ToDenisChenu  
PrioritynoneSeverityminor 
Status assignedResolutionopen 
Product Version3.x 
Target VersionFixed in Version 
Summary12086: Review the way of translation for plugin
Description

@olle add a translation system for plugin, but i think there are better option.

I think

  • we must , if able, don't update Yii system (use framework in the best way we can)
  • we must allow plugin dev to use his translation way : php file/sql/gettex (po/mo) / own function (api why not)
Steps To Reproduce

none ;)

Additional Information

The actual way on develop is here : https://github.com/LimeSurvey/LimeSurvey/commit/2b2ac333dd867b7821e60c420ac45420f6eb9ddf
I think this function can be replaced by another system

See a Proff Of concept (working concept) https://framagit.org/SondagePro-LimeSurvey-plugin/maintenanceMode/blob/3ef3ca4a399fb1debfc4ab17ae419d1bc5e4ec25/maintenanceMode.php#L286

The idea is :

  • if plugin have translation (in json file[1] for example)
    => create a new component in loadPlugin [2]
  • update gT [3] function : to allow $source[4] to be set and use it see the example[5]
  • Add a API gT who send the class name of the actual plugin to gT

Then :

  1. a plugin have the api to call his translation
  2. a plugin can use another plugin translation using gT($string,'html',null,'otherPlugin')
  3. The plugin dev can create his translation file the way he want, even with own http://www.yiiframework.com/doc/api/1.1/CMessageSource Class

The hardest part are:

  • How get message source in config.json :
    • translation:mo
    • translation:po
    • translation:php
    • translation:sql (but here : db name / table ??? other )
    • translation:myClass

Maybe :

  1. https://github.com/LimeSurvey/LimeSurvey/commit/2a065c28d6799b643806b818b00e3428ead5dc55
  2. https://github.com/LimeSurvey/LimeSurvey/blob/develop/application/libraries/PluginManager/PluginManager.php#L286
  3. https://github.com/LimeSurvey/LimeSurvey/blob/develop/application/helpers/common_helper.php#L37
  4. http://www.yiiframework.com/doc/api/1.1/YiiBase#t-detail
  5. https://framagit.org/SondagePro-LimeSurvey-plugin/maintenanceMode/blob/3ef3ca4a399fb1debfc4ab17ae419d1bc5e4ec25/maintenanceMode.php#L293
TagsNo tags attached.

Activities

DenisChenu

DenisChenu

2017-01-27 09:41

developer   ~42843

Last edited: 2017-01-27 09:44

View 3 revisions

some idea about config:

{
"translation": {
"po": {}
}
}
=> po file, default config : https://framagit.org/SondagePro-LimeSurvey-plugin/maintenanceMode/blob/master/maintenanceMode.php#L222

{
"translation": {
"php": {
"basePath": "pathRelatedToPluginDir.YiiWay"
}
}
}
=> php file with basePath (default are locale for sure ;) )

Or maybe:
{
"translation": {
"type": "po"
}
}
=> po file , default config

{
"translation": {
"type": "db",
"config": {
"tableName": "pluginName",
"dbConnection": "completeNewDbConnexion, default to LS db",
"sourceTableName": "pluginNameSourceMessage",
"translatedTableName": "pluginNameMessage"
}
}
}
here : a new table (plugin must set it, or maybe adding it when install, can review this in new feature without problem) (the tableName/sourceTableName/translatedTableName are all the default)

I think starting by :

  • Just allow po/mo and php (it's the most easy) in config
  • When we have a solution to add db or ownClass => it's a new feature
DenisChenu

DenisChenu

2017-01-27 09:42

developer   ~42844

type + config seem better (for my POV)

DenisChenu

DenisChenu

2017-01-30 12:42

developer   ~42868

create default translation if local exist : can be a solution too

@olle spoken for an 'auto load translation if able'

ollehar

ollehar

2017-01-30 12:53

administrator   ~42869

Or a default translation config if omitted.

DenisChenu

DenisChenu

2017-01-30 13:15

developer   ~42870

yep :)

locale directory exist => create the language component :)
or (if dev want to use another dir : use config.json)

The difficulty seems to be :

  • if i use gT(or eT or ...) in a plugin : what must be done
    1. Call plugin language
    2. or call LS core default language

Quick solution ls\pluginmanager\LimesurveyApi->gT(string) call this plugin translation

ollehar

ollehar

2017-01-31 15:06

administrator   ~42911

Can you point to the specific place in code that was a problem with my implementation? Did I hack core Yii code?

DenisChenu

DenisChenu

2017-01-31 15:28

developer   ~42912

No really an error : just :

  • why rewriting loadMessage ?
  • because rewriting loadMessage, i think it broke other messageSource

My objective is to finally have the easiest and most adaptable way to have translation for plugin.

View you code : one (newClass + 1 function) + one way to have message : https://github.com/LimeSurvey/LimeSurvey/commit/2b2ac333dd867b7821e60c420ac45420f6eb9ddf#diff-de5ed4c534457ee3003a9ae2352e4eceR49 + no separation between plugin (same string by different plugin : i didn't track what happen here).

There still a lack of feature in the 2 implementation : replace default core string ......

Maybe we have to find a way for this one too.

PS : i think using locale/en/en.po is missused : locale/en/message.po seems OK, and more : we can have (in future) locale/en/public.po / locale/en/admin.po / locale/en/wtf.po :)

Issue History

Date Modified Username Field Change
2017-01-27 09:31 DenisChenu New Issue
2017-01-27 09:41 DenisChenu Note Added: 42843
2017-01-27 09:41 DenisChenu Note Edited: 42843 View Revisions
2017-01-27 09:42 DenisChenu Note Added: 42844
2017-01-27 09:44 DenisChenu Note Edited: 42843 View Revisions
2017-01-30 12:42 DenisChenu Note Added: 42868
2017-01-30 12:46 DenisChenu Additional Information Updated View Revisions
2017-01-30 12:53 ollehar Note Added: 42869
2017-01-30 13:15 DenisChenu Note Added: 42870
2017-01-31 15:06 ollehar Note Added: 42911
2017-01-31 15:28 DenisChenu Note Added: 42912
2017-06-18 11:33 DenisChenu Assigned To => DenisChenu
2017-06-18 11:33 DenisChenu Status new => assigned