General Rules
- Source strings should be in English.
- Make sure all user-viewed text gets run through a translation function.
- Never translate HTML classes or code.
- Always use a succinct definition string.
- Avoid jargon or regional dialect.
- Sentences should end in punctuation.
- Avoid repeating phrases when not needed. For example, if you already have a heading that says "Buttons", prefer using a label like "Color" instead of "Button Color".
- Do NOT include HTML in translation strings.
- Avoid concatenating strings together to before/after a translation. This make source strings harder to track down, and can lead to grammatically incorrect string after translation.
Translation in PHP
There are a few function available for translating source strings.
Gdn::translate('Some String');
t('Some String');
t('Some String', 'Fallback String');
Translating String with HTML
Work in Progress.
Translation with Smarty (Legacy Themes)
{t c="This the proper way to do translation strings in a TPL"}
Translation with Twig Templates
{{ t("This the proper way to do translation strings in Twig") }}
Translation in Javascript
import { t } from "@vanilla/i18n";
// DO NOT EVER TRANSLATE IN THE TOP LEVEL OF A FILE OR STATIC VARIABLE
// It doesn't work because the translation hasn't been initialized yet.
t('Some string'); // Won't work
() => t('Some String');
() => t('Some String', 'Fallback String');
() => <Translate source="Some String with <0>HTML</0>" c0={content => (<strong>{content}</strong>) } />