Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
3

Translations for readmes on .org are done through https://translate.wordpress.org. You could contribute translations for your own plugin if you wanted. Start by picking a locale/language you want to translate into, search for your plugin, and select the Readme Sub Project. You don't need to do anything special to the readme itself.


3

If you'd like to try itstool, you just need to give it a custom ITS rules file for your format. The following rules works for the snippet you posted: <its:rules xmlns:its="http://www.w3.org/2005/11/its" its:version="1.0"> <its:translateRule translate="yes" selector="//@label"/> </its:rules> Save this as, say, options.its, then ...


3

You should use a localized XML format like XLIFF or TMX , there is a tool to convert XLIFF to .po. If you cannot change the source XML you have a few options but it really depends how your outputting this XML info: Parse the XML ( for label) and create a .po with gettext output for these strings (then possibly merge the .po files). Duplicate the XML ...


3

Your theme's text domain is defined in your Theme Header in style.css. For example: /* * Plugin Name: My Plugin * Author: Otto * Text Domain: my-plugin */ The text domain should match your theme's 'slug' (ie. the name of the folder where your theme is stored). Read more: https://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains


2

Turns out that wordpress uses context strings for this piece of text: _x('Add New', 'post') and _x('Add New', 'page') This is because the string 'Add New' is different depending on the following noun in some languages. i.e in Danish: 'Add New Post' => 'Tilføj Nyt Indløg' 'Add New Page' => 'Tilføj Ny Side'. Notice the added 't' in 'Nyt'. Might be helpful ...


2

Use the __() function, just as you see in the the_content() example: <?php echo get_the_term_list( // ID $post->ID, // taxonomy 'book', // Before __( 'Books: ', 'ft' ), // Separator, see http://core.trac.wordpress.org/ticket/7897 __( ', ' ), // After ' ', // Looks like you've added an extra parameter? ...


2

The WordPress way to do this is the wp_localize_script() function. When you enqueue a script, also add a call to wp_localize_script(): wp_register_script( 'my-script', 'path/to/script.js' ); wp_localize_script( 'my-script', 'myScript', array( 'msg_must_match' => __( 'Message must match', 'my-plugin-domain' ), ) ); This creates a global JavaScript ...


2

There is no way to know if string should be translatable or not (should a 'fail' in a json response be translatable?). Some things just need proper code review and can not be automated.


1

I did manage to solve this later on by using WPML, but over time found that WPML is quite bloaty and slow, support not very good, and if you need only 1 language (but original strings for theme are in English and the language you need is not) or perhaps 2, you do not need it. The only thing you need is: Set LOCALE in your theme .env or wp-config.php. An ...


1

Everything you have tried should have worked perfectly, I am not sure why is this not working, I am modifying your code a little bit to check for post type, check if it can help you, function rename_publish_button_to_review( $translation, $text ) { if( !current_user_can('administrator') && 'post' == get_post_type() ) { if( 'Publish' =...


1

WordPress doesn't automatically translate anything, you need to use the __ and _e functions, even in your config file, if you want it to be translateable. define( 'CONSTANT', __( 'some string', 'textdomain' ) );


1

PHP can read the 'HTTP_ACCEPT_LANGUAGE' header from the browser request, but this might not be easy to parse if there is more than one accepted language set. For the simplest case, when one language is set as accepted, you need to read only first 2 characters from this header: $language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); But, most WordPress ...


1

My first thought would be to wrap the string in a trim() statement: <?php _e( trim($text), $domain ) ?> Would this do what you are wanting it to do or did I misunderstand your question? EDIT: On looking further at the docs, while technically you may be able to get away with passing a variable, you should not pass variables into translation ...


1

I think this is happening because Constants cannot be redefined later. Once they are set, they are fixed. http://php.net/manual/en/language.constants.php I'm not exactly sure how WP language constructs work, but part of me thinks that they are defined, then changed later on the fly when plugins/themes use them. I don't have a reference for this but it seems ...


1

Wrap the elements of $search and $replace arrays into __() function to get the translated strings: function search_replace_search() { $search_term = esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) ); // Get search term $search = array( __('word1'), __('word2') ); $replace = array( __('...


1

Your code use load_theme_textdomain. If you are in child theme and need to load translated strings, use function load_child_theme_textdomain. Please take a look this answer too Override parent theme translation on child theme.


1

WordPress doesn't quite have a practice of localizing something that isn't core/plugin/theme. My educated guess would be that it will work just fine with same concepts, but you will have to write custom loading logic. Use lower level load_textdomain(), since higher level functions are meant for plugins/themes specifically. As long as you determine and load ...


Only top voted, non community-wiki answers of a minimum length are eligible