• Resolved Grant McN

    (@grant-mcn)


    Hello,

    I am developing an African languages website and would like to use TranslatePress to do it but I have a few questions:

    1. Is there a way to find out which 221 languages are covered in your Extra Languages add-on? Or should I say, are any of them African languages?
    2. To add custom languages, do I need to add the below code and edit it for each additional language? And then re-upload the plugin?

    :

    */
    add_filter( 'trp_wp_languages', 'trpc_add_custom_somali_language', 10, 2 );
    function trpc_add_custom_somali_language( $languages ){
    
        $lang = 'so';
    
        if( array_key_exists( $lang, $languages ) ){
            return $languages;
        }
    
        // Somali
        $languages['so'] = array( 'language' => 'so_SO', 'english_name'=> 'Somali', 'native_name' => '˜اَف صَومالي', 'iso' => array( 'so' ) );
    
        global $TRP_LANGUAGE;
    
        if( $TRP_LANGUAGE == 'so_SO' ){
            $GLOBALS['text_direction'] = 'rtl';
        }
    
        return $languages;
    }
    
    add_filter('gettext_with_context', 'trpc_somali_rtl', 10, 4);
    function trpc_somali_rtl($translated, $text, $context, $domain){
        global $TRP_LANGUAGE;
        if($text == 'ltr' && $context == "text direction" && $TRP_LANGUAGE == 'so_SO'){
            $translated = 'rtl';
        }
    
        return $translated;
    }
    
    add_filter( 'trp_flags_path', 'trpc_flags_path_somali', 10, 2 );
    function trpc_flags_path_somali( $original_flags_path,  $language_code ){
    
        // only change the folder path for the following languages:
        $languages_with_custom_flags = array( 'so_SO' );
    
        if ( in_array( $language_code, $languages_with_custom_flags ) ) {
            return  plugin_dir_url( __FILE__ ) . 'flags/' ;
        }else{
            return $original_flags_path;
        }
    }

    Thanks,

    Grant

    • This topic was modified 5 years, 11 months ago by Grant McN.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello Grant,

    You have the ability to select any one of the 221 languages that we added to the plugin even if you dont own the addon.

    If you cannot find the language that you need you can add it with the code you already mentioned. Yes, the best approach would be to create a new “plugin” for each language..

    Let me know if you manage to use the custom language in your project.

    Kind regards,

    Thread Starter Grant McN

    (@grant-mcn)

    Thanks, Denis. Only one of the 221 languages you have added are useful to me. This means I have many custom languages to add. A new plugin for each language sounds excessive. Can I not replicate that code and make small changes for each new language and then include all of it in one “Custom African Languages” plugin? Does CozmoLabs do paid consulting to help with these kinds of projects (that will ultimately benefit your plugin)?

    Hello Grant,

    You could do that. but my suggestion would be to keep it simple and create an addon for your secondary language.

    Unfortunately we are not available for custom work.. but if the users keep asking for a language we will add it in our main plugin for sure!

    Thanks for understanding,

    Kind regards,

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding custom languages and flags’ is closed to new replies.