• Resolved ocianciarelli

    (@ocianciarelli)


    Hello!

    I asked WPML how to make a hard-coded text in the home page to show up in different languages.

    They told me to add the following code but told me to ask the author what is the [name of your text domain]. Please see below.

    Could you please help me out??? Thank you so much!!

    <?php if(is_home() && !is_paged()):?><div align=”center”>
    <span style=”font-size: large;”>
    <?php
    $line_break = “
    “;
    sprintf( __(‘Yellow Bridge is an international knowledge center that inspires %s and supports small and medium organizations
    to improve their performance through sustainability.’, [name of your text domain] ), $line_break );
    ?>

    </span></div><?php endif;?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Name of textdomain for Customizr theme is “customizr”.

    Thread Starter ocianciarelli

    (@ocianciarelli)

    Thank you!

    It doesn’t work though ??
    how should I write it? If I write it between [] the page is down. If I write it without it, the text doesnt show up anymore (neither in the original language). They told me I have to past that on the functions.php file. but it doesn’t work. I am probably doing something wrong… (this is al ery new to me)

    Thank you so very much for your help

    I’m provably wrong but you need to change [name of your text domain] for ‘customizr’.
    ( included)
    But I don’t know where you should put this code… that’s all I can help you. Hope it’s enough.

    Yes, you need to put it in between single or double quotes. It’s php. On the other hand, I don’t think the above function will work, though. When you put “customizr” in textdomain, it searches the xx_XX.mo file from Customizr folder for the translation of

    Yellow Bridge is an international knowledge center that inspires %s and supports small and medium organizations
    to improve their performance through sustainability.

    But that text is not part of the language files of Customizr, so it will never get translated (it will be displayed untranslated). In order to get it translated you have to declare a textdomain for you child theme, create a pot file for it, set the child theme folder as source path in the file’s settings and hit “Update from sources” in poedit. At that point your child theme’s pot file will be updated with your string and you may create a xx_XX.po (and a xx_XX.mo subsequently) for your language, in your child theme’s declared textdomain folder and provide a translation for your text. You could do all the above in Customizr, but you’ll lose it upon update, that’s why I suggested you do it in child theme folder. It’s complicated, and it’s something only theme and plugin developers should be doing, not the end user, in order to internationalize their code.

    Are you sure you got the solution right from WPML? Because, if you did, they forgot to tell you how to implement it. ??

    I’ll give you the steps you need to do, assuming your child theme is Customizr Child:
    1. Create a child theme with the name of Customizr Child.(if you haven’t already).
    2. Create a lang folder inside it.
    3. Add this php code to your child theme’s functions.php:

    add_action( 'after_setup_theme', 'customizr_child_theme_setup');
    function customizr_child_theme_setup() {
        load_child_theme_textdomain( 'customizr-child', get_stylesheet_directory() . '/lang' );
    }
    
    add_action ('__header', 'display_homepage_slogan', 100);
    function display_homepage_slogan() {
    	ob_start();
    	if(is_home() && !is_paged()):
    		echo '<div align="center">
    		<span style="font-size: large;">';
    		$line_break = "<br />";
    		printf( __('Yellow Bridge is an international knowledge center that inspires %s and supports small and medium organizations
    to improve their performance through sustainability.', 'customizr-child' ), $line_break );
    		echo '</span></div>';
    	endif;
    	echo ob_get_clean();
    	}

    4. Download, install and open Poedit.
    5. File > New. Instert your language code in there (let’s assume it’s french: you need to type fr_FR in the input that shows up).
    6. Go to Catalog > Properties and put there:

    Project name and version: Customizr Child
    Team: put your name there
    Team’s email address: put your email there (it’s safe)
    Charset: UTF-8 (recommended)
    Source code charset: UTF-8 (recommended)

    7. Save the catalog inside the lang folder as fr_FR.po (use your own language locale, of course – ro_RO.po for romanian, etc…)
    8. Go to Catalog > Properties and open the second tab. Put ../ (dot-dot-slash) as base path and add a . (dot) path (2nd icon). Click save.
    9. Click Update. Your Yellow Bridge… text should now show up in the translations.
    10. Select it and input your translation in the Tranlation field. Watch for the position of %s (that will be your line break).
    11. Save again.
    12. Now upload all your lang folder and functions.php of your child theme to your server.

    Your text should correctly display in the selected language now.

    Thread Starter ocianciarelli

    (@ocianciarelli)

    Thank you VERY much for all the tips you give. I was trying this out but it was not working, I was getting an error when I was updating (point 9).
    Right at that moment I got an answer from WPML with a new code wich did work! So my problem is solved.

    I am very grateful for your help.

    Kind regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘'name of text domain' hard-coded text in the home page’ is closed to new replies.