Using wordpress translations strings in plugin

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 … Read more

How can I see my theme’s text domain?

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

Using WordPress gettext functions in a library outside plugin or theme scope

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 … Read more

How to set translations in javascripts for my plugin?

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 object called myScript that will contain the keys and values passed … Read more

Ajax – gettext without a plugin

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 … Read more

Can’t we use strings defined as PHP constants if we want to translate them in a plugin?

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 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)