TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
×
Menu
Index

Dịch trong theme

 
Chúng ta đã học cách sử dụng hàm tạo/dịch chuỗi trong wordpress ví dụ _e(, _(, __(
- Để dịch chuỗi trong theme, bạn cần nạp ngôn ngữ chuyển đổi trong phạm vi theme với tên nhóm ngôn ngữ bạn viết cho theme. Chúng ta bắt đầu nạp ngôn ngữ với tên nhóm xác định.
load_theme_textdomain( 'hoangweb', TEMPLATEPATH.'/languages' );
Trong đó:
 
Chú ý: tên cho textdomain, cho phép mọi ký tự cả dấu cách.
 
Debug:
Kiểm tra tên file ngôn ngữ  (tương ứng với ngôn ngữ đang kích hoạt cho wordpress) có tồn tại trong thư mục nạp ngôn ngữ gọi bởi hàm load_theme_textdomain không? viết lại đoạn code sau  vào theme functions.php
Để chắc chắn không bị mất file .mo này.
$result=load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
if(!$result){
     $locale = apply_filters( 'theme_locale', get_locale(), 'twentytwelve' );
     echo ( "Could not find $path/$locale.mo." );
}
Note:
 
- Bạn có thể tải nhiều gói ngôn ngữ cho nhiều nhóm ngôn ngữ khác nhau sử dụng cho theme hiện tại.
load_theme_textdomain( 'textdomain1', TEMPLATEPATH.'/languages' );
load_theme_textdomain( 'textdomain2', TEMPLATEPATH.'/languages1' );
load_theme_textdomain( 'textdomain3', TEMPLATEPATH.'/languages2' );
Ví dụ: tôi tạo 3 textdomain là: textdomain1, textdomain2, textdomain3 dịch cùng 1 chuỗi.
__("string1","textdomain1");
_e("string1","textdomain2");
_("string1","textdomain3");
 
- Thiết lập mặc định textdomain sử dụng trong suốt theme bằng cách khai báo vào thuộc tính Text Domain trong phần mô tả theme style.css trong thư mục theme.
/*
Theme Name: Twenty Twelve
Theme URI: http://wordpress.org/themes/twentytwelve
Author: the WordPress team
Author URI: http://wordpress.org/
Text Domain: twentytwelve
*/
 
Do đó bạn không cần chỉ định tên textdomain ở tham số thứ 2 của hàm chuyển đổi chuỗi nữa.
__("abcde");
 
 
Made with help of Dr.Explain

Unregistered version