Today I wanted to be able to pass a custom field variable to the WordPress localization (l10n) functions. The custom field is a select field, so all the possible outputs are known.
WordPress uses PO and MO files for translations. These are generated by scanning the site for __()
and _e()
functions, with a programme such as Poedit, to generate the list of translatable strings.
Using variables in these functions, like _e($output, 'text-domain')
, causes a problem. When the scan is done, there is no string to add to the PO file.
In my case, because the outputs are known, I created a file called manual-translations.php
, included it from my functions.php
file and added the translatable strings like:
[code]__( ‘String one’, ‘text-domain’ );
__( ‘Second string’, ‘text-domain’ );
__( ‘Stringy cheese’, ‘text-domain’ );[/code]
Now when the site is scanned it picks these up and I can now add the translations in Poedit.
Hope that helps someone out there!
Leave a Reply