0

The second parameter in the translate function is optional, but I always see people use it and some don't.

So I want to know if I should use it or not and if yes, how I will use it later.

I asking this because I'm new to this, and I'm using e() and _() right now in my theme, and I'll learn how to translate it when I finish.

Thanks in advance

1 Answer 1

3

Welcome to WPSE Peter,

The second argument is a translation domain. This is essentially where the translation for the first argument can be found. By default it checks the WordPress language folder - but if you are creating a custom theme or plug-in, you cannot rely on the translation for that string to be there (after all the WordPress language folders only contain translations for WordPress, not your plug-in/theme).

The setup is different for plug-ins, but to register a text domain for themes you use load_theme_textdomain:

add_action('after_setup_theme', 'my_theme_setup');
function my_theme_setup(){
    load_theme_textdomain('my-unique-theme-domain', get_template_directory() . '/languages');
}

The first argument is the domain name, which is passed as the second argument in _e() and __(). The second is where the translation files can be found.

See Codex for _e() and __().

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.