I use it on wordpress
sample
Code: Select all
<?php _e( 'Some text to translate and display.', 'textdomain' ); ?>
these function use .pot /.mo files, you can edit these files with Pedit application
But someone can convert to our language simply by converting this function
the source of this function is
function _e( $text, $domain = 'default' ) {
echo translate( $text, $domain );
}
sample
_e( string $text, string $domain = 'default' )
In this function,the “$domain” is used to locate the multilingual file.(The file which is the translation of your theme.)
In wp-include there is a function related to this var
Code: Select all
function load_theme_textdomain( $domain, $path = false ) {
$locale = apply_filters( 'theme_locale', get_locale(), $domain );
if ( ! $path )
$path = get_template_directory();
// Load the textdomain from the Theme provided location, or theme directory first
$mofile = "{$path}/{$locale}.mo";
if ( $loaded = load_textdomain($domain, $mofile) )
return $loaded;
// Else, load textdomain from the Language directory
$mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
return load_textdomain($domain, $mofile);
}
function translate source
Code: Select all
function translate( $text, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate( $text );
/**
* Filters text with its translation.
*
* @since 2.0.11
*
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
return apply_filters( 'gettext', $translation, $text, $domain );
}
Code: Select all
function apply_filters( $tag, $value ) {
global $wp_filter, $wp_current_filter;
$args = array();
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
$args = func_get_args();
_wp_call_all_hook( $args );
}
if ( ! isset( $wp_filter[ $tag ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
return $value;
}
if ( ! isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
}
if ( empty( $args ) ) {
$args = func_get_args();
}
// don't pass the tag name to WP_Hook
array_shift( $args );
$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
array_pop( $wp_current_filter );
return $filtered;
}