Loading...
 
Skip to main content

Strings Format Convention

About

This page is for developers and theme creators who edit strings to translate (mainly the *.tpl files). In order to minimize the language file, and to have the same look across Tiki, some rules need to be followed.
Some are arbitrary, some are for correct English. Feel free to propose other rules.

English conventions (capitalization)

  • in a menu, if it's a main Tiki feature or a named section each first letter of significant words is upper case, otherwise (when it's a request for an action) the string has an upper case first letter only
    • Ex: {tr}Image Gallery{/tr} {tr}System Admin{/tr}
      but
      {tr}Submit a new link{/tr} {tr}List surveys{/tr}

Tables of listings

  • in a column header, the label is upper case first letter only
    • Ex: {tr}Name{/tr} {tr}Last author{/tr}

Forms

  • a text near radio button switch has an upper case first letter only
    • Ex: {tr}Yes{/tr}
  • before a text input, the label has an upper case first letter only and is followed by ":"
    • Ex: {tr}Upload picture:{/tr} not {tr}Upload picture{/tr}:
      Note: placing the ":" string inside the translation allows languages to choose whether to omit, use ": ", " : ", " :-", or something else.

Other

  • in a title, each first letter of significant words is upper case
    • Ex: {tr}Messages and Strings Format{/tr}
  • the same applies to labels of actions or button links
    • Ex: {tr}Create a New Structure{/tr} {tr}Export{/tr} {tr}Cancel Edit{/tr}

Localized strings

Dealing with variables

PHP and Smarty variables should never be placed directly inside localized strings.
Instead, always use placeholders or translate only the static part of the text.

  • PHP: use tr("Changed from %0 to %1", $old, $new) instead of tr("Changed from $old to $new")
  • Smarty: use {tr _0=$old _1=$new}Changed from %0 to %1{/tr} instead of {tr}Changed from $old to $new{/tr}


Wrong (variable inside ):
{tr}{$diagnostic_composer_location}{/tr}

This is incorrect because the translation system extracts the literal string {$diagnostic_composer_location}, which is meaningless for translators and will never match any real text at runtime.

Correct:
Translate only the static label and output the variable separately.

Copy to clipboard
<strong> {if $diagnostic_composer_location} {tr _0=$diagnostic_composer_location}Composer: %0{/tr} {else} {tr}Composer not found{/tr} {/if} </strong>

The problem with variable is that strings for translation are extracted from the source code while to display them to the user they are interpreted by PHP. So, for example, the string below:

$comments_cant comments

Translators will see the above string as it appears in the source code ( $comments_cant comments ) but in the application $comments_cant will be replaced by the variable value. Tiki will never find the translation for "10 comments" or any other value of $comments_cant.

Best practices

  • Avoid slang and abbreviations.
  • Use entire sentences since word order change from language to language.
  • Use placeholders instead of variables inside the string (explained above).
  • Any sentence should end with the complete punctuation. (like preferences descriptions)


Based on suggestions from Gettext manual.

Common mistakes

Below is a list of examples of what you should NOT do (they were all extracted from Tiki and need to be fixed):

  • Wrong: tra('To send an email once the tracker item has been created. Format: from').'|'.tra('to').'|'.tra('template')
    Correction: tr('To send an email once the tracker item has been created. Format: from|to|template')
  • Wrong: {tr}There are no wiki pages similar to '{$page}'{/tr}
    Correction: {tr _0=$page}There are no wiki pages similar to '%0'{/tr}

Contextual translation strings

Please see Contextual translations!

Other considerations for developers


Learn how to run get_strings.php and do the following:

  • Spellcheck your strings. If you save the old -+language.php+- file, you only need to spellcheck the difference. Translators have to "retranslate" spelling corrections
  • If you improve an English string, please consider pages Mass spelling correction and Pending text corrections in order to avoid extra work for translators
  • Look in (the English) -+lang/en/language.php+- and see if there is a phrase that you could use. There are already too many variants, e.g.;
    • Create/Edit xxx
    • Create/edit xxx
    • Create or edit xxx
    • edit/create
    • create/edit
    • Edit or Add xxx
    • Add or Edit xxx
    • Add or edit xxx
    • click to edit
    • edit
    • edit this xxx
    • edit new xxx

Although some of the variants above might have a justification it seems like creativity is winning over conformance...

  • Stay with one possible variation if there are more in English when defining new strings to be translated, e.g.:
    • Use email everywhere instead of e-mail


We should plan to switch to using tokens and default strings - discussion over at I18n

Alias

Collapse/expand modules below
Show PHP error messages