Creating Translation Strings - HL Vanilla Community
<main> <article class="userContent"> <div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6030677/uploads/GF7M8QFXHVBK/microsoftteams-image-288-29.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6030677/uploads/GF7M8QFXHVBK/microsoftteams-image-288-29.png" alt="MicrosoftTeams-image (8).png" height="108" width="1356" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <h2 data-id="general-rules">General Rules</h2><ul><li>Source strings should be in English.</li><li><strong>Make sure all user-viewed text gets run through a translation function.</strong></li><li>Never translate HTML classes or code.</li><li>Always use a succinct definition string.</li><li>Avoid jargon or regional dialect.</li><li>Sentences should end in punctuation.</li><li>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".</li><li><strong>Do NOT include HTML in translation strings.</strong></li><li>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.</li></ul><h2 data-id="translation-in-php">Translation in PHP</h2><p>There are a few function available for translating source strings.</p><pre class="code codeBlock" spellcheck="false" tabindex="0">Gdn::translate('Some String'); t('Some String'); t('Some String', 'Fallback String'); </pre><h2 data-id="translating-string-with-html">Translating String with HTML</h2><p><em>Work in Progress.</em></p><h2></h2><h2 data-id="translation-with-smarty-(legacy-themes)">Translation with Smarty (Legacy Themes)</h2><pre class="code codeBlock" spellcheck="false" tabindex="0">{t c="This the proper way to do translation strings in a TPL"} </pre><h2 data-id="-1"></h2><h2 data-id="translation-with-twig-templates">Translation with Twig Templates</h2><pre class="code codeBlock" spellcheck="false" tabindex="0">{{ t("This the proper way to do translation strings in Twig") }} </pre><p><br></p><h2 data-id="translation-in-javascript">Translation in Javascript</h2><pre class="code codeBlock" spellcheck="false" tabindex="0">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>) } /> </pre><p><br></p> </article> </main>