![]() ![]() Replace my-plugin with your plugin name in the 1st and 3rd parameter of the load_plugin_textdomain function. Load_plugin_textdomain( 'my-plugin', false, 'my-plugin/languages' ) mo file, you can do it by using this code in the beginning of your plugin file: Somewhere in your plugin, you must tell WordPress to use your. Instruct the plugin to load translated text for the current language Whenever the plugin is updated with new text, update the po file, translate new strings and reupload the. po files for plugins like this: -.po, here are some examples: po file is crucial, it's composed of the concatenation of the plugin text domain (my-plugin) and the language locale (fr_FR), always name your. mo file is generated with the same name, the filename of the. Translate some or all the of the strings, save the. Save the catalog as /my_wordpress_blog/wp-content/plugins/my-plugin/languages/ my-plugin-fr_FR.po. Project info: Use your (or your team) information, change the language and country, I will use French and France.Using Podeit, create a catalog from a POT file (File › New catalog from POT file.): Now let's create the first translation (I will use fr_FR): When the update is finished close that catalog, you won't need to update that file unless you add new translatable strings (i.e enclosed in _() or _e()) to your plugin. Save the catalog as /my_wordpress_blog/wp-content/plugins/my-plugin/languages/ my-plugin.pot and scan your plugin files for translatable text by pressing the update button. , (we will store language file in a plugin subdirectory called languages) ![]() Project info: Use your (or your team) information, the language and country should match your plugin default language.Open Poedit and create a new catalog (File › New Catallog.) with these settings: po file, all you can do with these files is to upload or re-upload them whenever you create or update a. A.mo file: is automatically created by Poedit whenever you save a.po file: is a translation file you or someone else started, and maybe completed, WordPress doesn't use it. pot file: is put at your disposal by the plugin developer and it's used as a starting point to create new translations, WordPress doesn't use it. $my_text = sprintf(_('Hello %s', 'my-plugin'), $username) Printf(_('Hello %s', 'my-plugin'), $username) With _() and sprintf(): /** Get the username */ How to output dynamic text like: "Hello "? The second parameter is the text domain, you will be using it to tell WordPress that the text provided as the first parameter belongs to this plugin, you can use any name you want but I prefer to use the same name as I used for the plugin file of directory, I find it more intuitive. _e() will output the text whereas _() will return it. _e() and _() will provide the translation - in the current language - of the text provided as the first parameter. $my_text = _('Welcome to my plugin', 'my-plugin') Don't use echo or print() to produce text output, instead use the WordPress functions _() and _e(): /** Not localization friendly */ ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |