As mentioned in the comments, Always start with English string and translate that even if it's a one language only website, to ease the pain here's what I always do to keep the strings and translations contained to the theme itself:
open your THEMENAME.info.yml
file and add the following:
'interface translation project': THEMENAME
'interface translation server pattern': 'themes/custom/THEMENAME/translations/%language.po'
then create a translations
directory within your theme and there you can add your translation .po
files, eg. fr.po
for french or nb.po
for Norwegian
This is the syntax you need to have within your .po
file:
msgid "Hello World"
msgstr "Bonjour le monde"
So whenever you write Hello World
string in a t()
function or as a filter in twig file like so: {{ Hello World|t }}
it would know to import the translations from there
But how to trigger the translation import?
drush locale:check
- not necessary, but checks if there are any new strings added
drush locale:update
- Imports the translations and you're done
Note that you can add/run this to your deployment procedure as well and make your life easier, no need for UI translation, just add your string to your .po
file whenever you write hardcoded string into your files
Update: Didn't even notice we are talking Drupal 7, this refers to Drupal 8 for future readers