开发者

Localization of a wordpress theme without a textdomain

开发者 https://www.devze.com 2023-01-08 22:56 出处:网络
I have a wordpress theme without textdomain (i.e. e(x) and not e开发者_StackOverflow中文版(x,domain)). I also have the .po and .mo files in a folder under /themes/My Theme/localization (Notice the spa

I have a wordpress theme without textdomain (i.e. e(x) and not e开发者_StackOverflow中文版(x,domain)). I also have the .po and .mo files in a folder under /themes/My Theme/localization (Notice the space name in the my theme). I would like to activate fr_FR. I created fr_FR.po and .mo and changed the wp-config to add the locale for fr_FR. However, I am still not getting the french to work. I saw many sites telling you to add a load_theme_textdomain at the top of functions.php, but I do not know what would my textdomain be. Any help will be appreciated.

Youssef


To get theme localization working, you're going to need to go through your theme and add a domain to every _e() and __() function call. this:

_e('some text');
__('some other text');

Will have to become this:

_e('some text', 'your-domain');
__('some other text', 'your-domain');

Next you'll need to add this bit of code at the top of your functions.php file:

load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/localization' );

$locale = get_locale();
$locale_file = TEMPLATEPATH."/localization/$locale.php";
if (is_readable($locale_file))
    require_once($locale_file);

You can read more about it in this post.


Add your own text domain. I did this recently to a theme which was not designed for localization, so I'm posting what I did.

Add this to functions.php

load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/languages' );

where your-domain can be any name, but keep it uniform throughout all theme files.

Now go through all the theme PHP files, and do the following:

If you see _e('some text') then change it to _e('some text', 'your-domain');

If you see __('some text') then change it to __('some text', 'your-domain');

If you see "some text" without __() or _e() then,

If "some text" is used in a function call, then make it __() like above, including the text domain

If "some text" is just printed and not part of any function call, surrround it with a _e() like shown above, and don't forget the text domain.

Read the Wordpress internationalization and localization guide for more information.


After an unbelievably long string of forums going through the same steps of how to set it up when everything is working correctly, I finally found what was causing the issue for me.

If the server sets the global $locale before wordpress has a bash at it, then wordpress uses the server's locale settings (in the wp-includes/l10n.php file, the function get_locale).

The solution I used, is to set the global $locale right next to defining WPLANG...

global $locale;
$locale = 'am_AM';
define('WPLANG', $locale);
0

精彩评论

暂无评论...
验证码 换一张
取 消