Actions

Custom translation: Difference between revisions

From LimeSurvey Manual

mNo edit summary
(Marked this version for translation)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=Introduction=
<languages /> <translate>


Since LimeSurvey 5.4.0 you can have your own translation for all string in all included language with direct access to your database.
=Introduction= <!--T:1-->


<!--T:2-->
Since LimeSurvey 5.4.0 you can have your own translation for all strings in all included languages with direct access to your database.
<!--T:3-->
This system can be used if an existing translation is not compatible with your business needs.
This system can be used if an existing translation is not compatible with your business needs.


<!--T:4-->
It should be reserved for specific cases, since text modifications in the heart of LimeSurvey will again require a modification of your database.  
It should be reserved for specific cases, since text modifications in the heart of LimeSurvey will again require a modification of your database.  


You can use this method too for translating Survey Theme specific string.
<!--T:5-->
Furthermore, you can use this method for translating Survey Theme specific strings.


=How database translation works=
=How database translations works= <!--T:6-->


For database translation, LimeSurvey uses a method inspired by [https://www.yiiframework.com/doc/api/1.1/CDbMessageSource CDbMessageSource] from the Yii framework.
<!--T:7-->
For database translations, LimeSurvey uses a method inspired by [https://www.yiiframework.com/doc/api/1.1/CDbMessageSource CDbMessageSource] from the Yii framework.


<!--T:8-->
# find the string in SourceMessage table lime_source_message->message, get the id : lime_source_message->id
# find the string in SourceMessage table lime_source_message->message, get the id : lime_source_message->id
# if exist find the related transtaion in Message table lime_message->translation for current language lime_message->language with current id lime_message->id
# if exists, find the related translation in Message table lime_message->translation for current language lime_message->language with current id lime_message->id


LimeSurvey create the array with translation from po file (see [[Translating LimeSurvey]] for update this file), and aftre merge with all translation form database.  
<!--T:9-->
LimeSurvey creates the array with translations from po file (see [[Translating LimeSurvey]] for information how to update this file), and afterwards merges it with all translations from the database.  


Then the translation from the database are always return if exist.
<!--T:10-->
Then the translations from the database are always returned if they exist.


=Sample for _Submit_ button in english and french=
=Sample for “Submit” button in English and French= <!--T:11-->


You want to show _Validate_ and not _Submit_ for the submit button in all of yours survey (with a specific theme). If you just update the theme and replace gT('Submit') by gT('Validate') : it always shows _Validate_ in all language.
<!--T:12-->
You want to show _Validate_ and not _Submit_ for the submit button in all of your surveys (with a specific theme). If you just update the theme and replace gT('Submit') by gT('Validate') : it always shows _Validate_ in all languages.


==For all surveys with all theme==
==For all surveys with all themes== <!--T:13-->


<!--T:14-->
# Create the source message <code>INSERT INTO lime_source_message (id, category, message) VALUES (NULL, NULL, 'Submit');</code>
# Create the source message <code>INSERT INTO lime_source_message (id, category, message) VALUES (NULL, NULL, 'Submit');</code>
# Check the ID (if it's the 1st : ID is 1) and use it for next instruction
# Check the ID (if it's the 1st : ID is 1) and use it for next instruction
# Create the related translation : <code>INSERT INTO lime_message (id, language, translation) VALUES ('1', 'en', 'Validate'), ('1', 'fr', 'Valider'); </code>
# Create the related translation : <code>INSERT INTO lime_message (id, language, translation) VALUES ('1', 'en', 'Validate'), ('1', 'fr', 'Valider'); </code>


==Using your own theme (ecommended solution)==
==Using your own theme (recommended solution)== <!--T:15-->


This method use a solution with your own template, it updates the default string for all other language too/.
<!--T:16-->
This method uses a solution with your own template, it updates the default string for all other languages as well.


<!--T:17-->
# In [[Theme editor]] select the Navigation part
# In [[Theme editor]] select the Navigation part
# Search for <code>{{ gT("Submit") }}</code> (in navigator.twig)
# Search for <code>{{ gT("Submit") }}</code> (in navigator.twig)
Line 40: Line 54:
# Check the ID (if it's the 1st : ID is 1) and use it for next instruction
# Check the ID (if it's the 1st : ID is 1) and use it for next instruction
# Create the related translation : <code>INSERT INTO lime_message (id, language, translation) VALUES ('1', 'fr', 'Valider'); </code>
# Create the related translation : <code>INSERT INTO lime_message (id, language, translation) VALUES ('1', 'fr', 'Valider'); </code>
</translate>

Latest revision as of 10:21, 23 May 2024

Other languages:

Introduction

Since LimeSurvey 5.4.0 you can have your own translation for all strings in all included languages with direct access to your database.

This system can be used if an existing translation is not compatible with your business needs.

It should be reserved for specific cases, since text modifications in the heart of LimeSurvey will again require a modification of your database.

Furthermore, you can use this method for translating Survey Theme specific strings.

How database translations works

For database translations, LimeSurvey uses a method inspired by CDbMessageSource from the Yii framework.

  1. find the string in SourceMessage table lime_source_message->message, get the id : lime_source_message->id
  2. if exists, find the related translation in Message table lime_message->translation for current language lime_message->language with current id lime_message->id

LimeSurvey creates the array with translations from po file (see Translating LimeSurvey for information how to update this file), and afterwards merges it with all translations from the database.

Then the translations from the database are always returned if they exist.

Sample for “Submit” button in English and French

You want to show _Validate_ and not _Submit_ for the submit button in all of your surveys (with a specific theme). If you just update the theme and replace gT('Submit') by gT('Validate') : it always shows _Validate_ in all languages.

For all surveys with all themes

  1. Create the source message INSERT INTO lime_source_message (id, category, message) VALUES (NULL, NULL, 'Submit');
  2. Check the ID (if it's the 1st : ID is 1) and use it for next instruction
  3. Create the related translation : INSERT INTO lime_message (id, language, translation) VALUES ('1', 'en', 'Validate'), ('1', 'fr', 'Valider');

Using your own theme (recommended solution)

This method uses a solution with your own template, it updates the default string for all other languages as well.

  1. In Theme editor select the Navigation part
  2. Search for Template:GT("Submit") (in navigator.twig)
  3. Replace by Template:GT("Validate")
  4. Create the source message INSERT INTO lime_source_message (id, category, message) VALUES (NULL, NULL, 'Validate');
  5. Check the ID (if it's the 1st : ID is 1) and use it for next instruction
  6. Create the related translation : INSERT INTO lime_message (id, language, translation) VALUES ('1', 'fr', 'Valider');