How I can internationalize variables within the function _e () __ (), etc?
How I can internationalize variables within the function _e () __ (), etc?
How I can internationalize variables within the function _e () __ (), etc?
Have you tried to add/change language flag in wp-config.php file define (‘WPLANG’, ‘en_GB’); REF: Installing WordPress in Your Language
Translating dynamic strings
I would question “obviously” here. I get rather cryptic string C as result on my Windows machine. Since WP isn’t actually using native PHP functionality for any localization and handles it via core code, my best guess would be that is coming from server configuration in your case.
You can use __(), _e(), _x() or _ex() and your textdomain to make your theme or plugin translatable. I stripped your code snippet to the basics, so you will get the idea more easily: <select class=”widefat”> <?php foreach ( $this->getImageSizes() as $name => $atts ) : ?> <option value=”<?php echo $name; ?>” ?>> <?php echo … Read more
In short: it’s the so called »textdomain«. The longer explanation: If you look accurate on your first example, you’ll see, that this parameter is not the second parameter for the_content but for the Funktion __(): <?php the_content( __( ‘Continue reading <span class=”meta-nav”>→</span>’, ‘twentythirteen’ ) ); ?> This function is part of the internationalisation (»I18n«) functions … Read more
localize elements in database
Your use of $current_user is a little wrong, you should include the global $current_user or assign it to a variable, or shorter and cleaner just get_current_user_id(): add_filter(‘locale’, ‘change_lang’); function change_lang( $locale ) { if( $lang = get_user_meta( get_current_user_id(), ‘user_lang’, true) ) { return $lang; } return $locale; }
Remember to have the text domain along with the render functions (echo function). It means that, they should be: esc_attr_e(“Text needing to be translated”,”your_text_domain”);<br> esc_attr_x(“Text needing to be translated”,”your_text_domain”);<br> ___(“Text needing to be translated”,”your_text_domain”);
In case of someone see this, Following worked for me with 4 changes : translated files only in plugin lang dir using “init” hook instead of “plugins_loaded” and be sure strings to translate are loaded after this one using get_user_locale() to be sure to show the right language for logged users (if not logged, this … Read more