Translation language

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Translation language

Postby Silvio.Falconi » Thu Nov 07, 2019 10:25 am

Php use a function php_e() to translate strings and the html use easy _e()

I use it on wordpress

sample

Code: Select all  Expand view
<?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  Expand view
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);
}


You can see $domain is used in this file.Actually it’s used to locate the .mo file.So you must may sure it share the same name with your theme folder name

function translate source
Code: Select all  Expand view
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 );
}

 


function apply_filters source

Code: Select all  Expand view

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;
}

 


of course these functions run on wordpress but I think you can convert them to mod_harbour but I don't like how you do it
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 5 guests