I’m writing a plugin and i wanted to i18n correctly text which i’m storing in the db or in an external file. How should i do that?As of now we are generating pot files with wordpress and so all the Translatable text is in calls
__( 'text', 'plugin_name');
But there is some text i would like to store in the db or in another format and that i don’t know how to put into the POT files.
The only thing that come to my mind is to use arrays for these data structures so that i can translate the values, but are there other options?
Short answer: You don’t. Not with the I18N functions. Data in the database is data that can change, and should be translated via some separate means. Data in the code is hard-coded, and doesn’t change, and can be translated via the I18N functions.
If you want to store all your translatable text in a single PHP file as an array, and then reference it from elsewhere in the code, then that works fine.
If the text is in the database, you can’t translate it using a POT file. The entire point of translation is to set up a lookup against static strings used in your code. If the text is in the database, it’s not static, and can’t be translated.
Well, at least not with the standard i18n feature’s you’re trying to use.