Translation does not show

Hi, sorry…too difficult for me. Where I will add it in the function.php file? In the end? What else I need than just the translation?

Last time I added this:

add_filter( 'gettext', 'x_translate_these_strings', 20, 3 );

function x_translate_these_strings( $translated_text, $text, $domain ) {

	$locale = get_locale();

    $string_table =  array (
    		'fi' => array (

    				'Post Archive by Month' => 'your translation here',
    				'Read More' => 'your translation here',
    				'Below you\'ll find a list of all posts from ' => 'your translation here',

    		)
    );

    $translation = $string_table[ $locale ][ $translated_text ];

    return !empty( $translation ) ? $translation : $translated_text;

}

I don´t know, do I need to copy all this above again, or just add the new translation in somewhere in the middle. I am sorry, I am not familiar with the code at all — with copy-pasting - yes :wink:

Hi Anni,

Please add that code at the end of your child theme’s functions.php (not the main theme’s functions.php). And please follow Christians recommendation about the space.

Then you need to change the your translation here with your preferred translation.

These are what you just need to change once added to your child theme’s functions.php

    				'Post Archive by Month' => 'your translation here',
    				'Read More' => 'your translation here',
    				'Below you\'ll find a list of all posts from ' => 'your translation here',

Thanks!

Actually, now when I downloaded the function php, the translation place where there ready. I didn’t know that. I it´s done. Thank you!

Still missing some translation.

I tried to add this to function.php:

‘TYPE AND PRESS “ENTER” TO SEARCH’ => ‘KIRJOITA HAKUSANA JA PAINA “ENTER”’,
‘Search Results’ => ‘Hakutulos’,
‘Below you’ll see everything we could locate for your search of “yhteystiedot”’ => 'Alta löydät sisältöä, joka löytyi hakusanalla ',

After what I have added. The whole page did not work anymore. So, what I did wrong?

Hello Anni,

Please make sure that you have place the correct quotes and commas.
You should be using this:

add_filter( 'gettext', 'x_translate_these_strings', 20, 3 );

function x_translate_these_strings( $translated_text, $text, $domain ) {

  $locale = get_locale();

    $string_table =  array (
        'fi' => array (

            'TYPE AND PRESS "ENTER" TO SEARCH' => 'KIRJOITA HAKUSANA JA PAINA "ENTER"',
            'Search Results' => 'Hakutulos',
            "Below you'll see everything we could locate for your search of" => "Alta löydät sisältöä, joka löytyi hakusanalla",

        )
    );

    $translation = $string_table[ $locale ][ $translated_text ];

    return !empty( $translation ) ? $translation : $translated_text;

}

Hope this helps. Please let us know how it goes.

Hi!

If I just add this one in the end of the function php, the page not show anymore and gives an error: HTTP ERROR 500

I added just this one:

add_filter( ‘gettext’, ‘x_translate_these_strings’, 20, 3 );

function x_translate_these_strings( $translated_text, $text, $domain ) {

$locale = get_locale();

$string_table =  array (
    'fi' => array (

        'TYPE AND PRESS "ENTER" TO SEARCH' => 'KIRJOITA HAKUSANA JA PAINA "ENTER"',
        'Search Results' => 'Hakutulos',
        'Below you'll see everything we could locate for your search of' => 'Alta löydät sisältöä, joka löytyi hakusanalla',

    )
);

$translation = $string_table[ $locale ][ $translated_text ];

return !empty( $translation ) ? $translation : $translated_text;

}

Please help me where I need to add this and what I need to check. I don’t understand the message before. I have copied all and I changed a few marks to be ’ not ".

Hi Anni,

There was a typo error, please change this

'Below you'll see everything we could locate for your search of'

to this

'Below you\'ll see everything we could locate for your search of'

The \ is important , but could be any of these

"Below you\"ll see everything we could locate for your search of"
"Below you'll see everything we could locate for your search of"

It depends on what you use to wrap your string like ' or ". Use \ if you’ll add the same apostrophe.

Hope this helps.

Stil not working, it brokes my page:

add_filter( ‘gettext’, ‘x_translate_these_strings’, 20, 3 );

function x_translate_these_strings( $translated_text, $text, $domain ) {

$locale = get_locale();

$string_table =  array (
    'fi' => array (

        'TYPE AND PRESS "ENTER" TO SEARCH' => 'KIRJOITA HAKUSANA JA PAINA "ENTER"',
        'Search Results' => 'Hakutulos',
        'Below you\'ll see everything we could locate for your search of ' => 'Alta löydät sisältöä, joka löytyi hakusanalla',

    )
);

$translation = $string_table[ $locale ][ $translated_text ];

return !empty( $translation ) ? $translation : $translated_text;

}

Hi There,

Please update your code to this:

add_filter( 'gettext', 'x_translate_these_strings', 20, 3 );

function x_translate_these_strings( $translated_text, $text, $domain ) {

	$locale = get_locale();

	$string_table =  array (
		'fi' => array (

			'Post Archive by Month' => 'Tiedotearkisto',
			'Read More' => 'Lue lisää',
			"Below you\'ll find a list of all posts from " => 'Tiedotteet kuukaudelta ',
			'Category Archive' => 'Kategoriat',
			"Below you\'ll find a list of all posts that have been categorized as " => 'Tiedotteet, jonka kategoria on  ',

			)
	);

    $translation = isset($string_table[ $locale ][ $translated_text ]) ? $string_table[ $locale ][ $translated_text ] : '';

    return !empty( $translation ) ? $translation : $translated_text;

}

Let us know how it goes!

Thank you! Finally it´s done :slight_smile:

Bad news is that I still found something to be translated. Can I just add them after the last one? They are in the Search, so not in the same place on the page.

I hope there would be easier way to translate the text. Do you know is the po. translation now possible, since the whole thing started that there were something wrong?

Hi Anni,

They should be translatable using PO files but we’re not sure why it’s failing on your site. And if you’ll add new translation through a code, you simply need to edit that existing one instead of adding another block of code. Example, let say this part

'Post Archive by Month' => 'Tiedotearkisto',
			'Read More' => 'Lue lisää',
			"Below you\'ll find a list of all posts from " => 'Tiedotteet kuukaudelta ',
			'Category Archive' => 'Kategoriat',
			"Below you\'ll find a list of all posts that have been categorized as " => 'Tiedotteet, jonka kategoria on  ',

You’ll just need to add a new line separate by comma

'word' => 'word',
'word' => 'word',
'word' => 'word',

Example,

'Post Archive by Month' => 'Tiedotearkisto',
'Read More' => 'Lue lisää',
"Below you\'ll find a list of all posts from " => 'Tiedotteet kuukaudelta ',
'Category Archive' => 'Kategoriat',
"Below you\'ll find a list of all posts that have been categorized as " => 'Tiedotteet, jonka kategoria on  ',
'Search' => 'Hae'

And I just added 'Search' => 'Hae'.

I’ll continue checking about PO translation issue, but I can’t guarantee a solution as translation is very broad.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.