Main content:
● What are they?
● Internationalization
● Localization
● Multilingual (with WPML)
Event: April 2016 Saigon WordPress Meetup, April 16, 2016
Link: http://www.meetup.com/Saigon-WordPress/events/229629915/
4. Main Content
● What are they?
● Internationalization
● Localization
● Multilingual (with WPML)
5. What are They?
Internationalization (i18n) is the process of
developing your theme/plugin language, so it can
easily be translated into other languages.
Localization (l10n) describes the subsequent
process of translating an internationalized
theme/plugin.
Multilingual means there are more than one
language in sites.
6. Internationalization (1)
Wrong
echo 'WordPress is the best!';
Right (use gettext functions)
echo __( 'WordPress is the best!', 'my-text-domain' );
Wrong (don’t be clever!)
__( 'Translate me.' , $my_text_domain );
Right (no variable, constant… for text domains)
__( 'Translate me.' , 'my-text-domain' );
10. Internationalization (5)
Date and number functions:
- number_format_i18n()
- date_i18n()
Escape functions:
esc_html__()
esc_html_e()
esc_html_x()
esc_attr__()
esc_attr_e()
esc_attr_x()
11. Internationalization (6)
Load .mo files:
function my_plugin_load_plugin_textdomain() {
load_plugin_textdomain( 'text-domain', FALSE,
basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded',
'my_plugin_load_plugin_textdomain' );
Last but not least: original language = ENGLISH
12. Localization (1)
File Types
● POT (Portable Object Template)
#: plugin-name.php:123
msgid "Page Title"
msgstr ""
● PO (Portable Object)
● MO (Machine Object)
13. Localization (2)
Generates POT / PO / MO files
● Plugin Repository Admin Tools
● WordPress i18n tools
● Grunt
● WPML String Translation
● MO files:
○ msgfmt -o filename.mo filename.po
○ Online tools
○ grunt-po2mo
15. Localization (4)
Feel localization!
● Settings > General > Site language
● Put the correct folders
○ wp-content/languages/plugins/text-domain-vi_VN.mo
○ wp-content/plugins/my-plugin/languages/text-domain-vi_VN.mo
16. Localization (5)
Contribute: Everyone can help
● https://wpvi.wordpress.com/
● https://translate.wordpress.
org/locale/vi/default/wp/dev
● https://translate.wordpress.org/projects/wp-
plugins/woocommerce
18. Multilingual (1)
Gettext strings
● Important: theme and plugins are ready for
internalization/localization.
● Use .mo files
● Use WPML > String Translation
19. Multilingual (2)
Options - translate in WPML String Translation
● Automatically: wpml-config.xml
● Manually: adding strings in wp-admin
24. Multilingual (7)
Common issues:
● Translate custom strings
- wpml_register_single_string
- wpml_translate_single_string
● wp_query($args) or get_posts($args) doesn’t
filter out correct posts IDs for the current
language
- add "suppress_filters=0" to arguments.
25. Multilingual (8)
Common issues:
● A custom post is different in a second
language
$post = get_post(
apply_filters( 'wpml_object_id', $post->ID, 'cpt' ) );
● A custom taxonomy ID is different in a second
language
$tax_id =
apply_filters( 'wpml_object_id', $tax_id, 'tax' );