This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
This topic contains 17 replies, has 3 voices.
Last updated by sarah.n 6 years, 11 months ago.
Assigned support staff: Andrey.
Author | Posts |
---|---|
February 24, 2014 at 8:47 am #346033 | |
thomasC-4 |
Hi WPML, is there a shortcode that you place into your posts and pages that takes the correct language (i.e. translation) and places it into the post/page? The reason is I have a lot of reoccurring text on my site. I thought this was string translation did but it seems not. Cheers Thomas |
February 24, 2014 at 11:41 am #346179 | |
Andrey Supporter Timezone: Europe/Kiev (GMT+02:00) |
Dear Thomas, Thank you for contacting to us ! Unfortunately,there is no shortcode that you can use inside within post/pages. It was added as a feature request to our todo list. Thank you, |
February 24, 2014 at 4:53 pm #346450 | |
sarah.n Supporter
Languages: English (English ) German (Deutsch ) |
Thomas, This is Sarah here. Can you please elaborate as to what exactly you are trying to do with the shortcode? You wrote: "...a shortcode that you place into your posts and pages that takes the correct language (i.e. translation) and places it into the post/page" Can you show me what you mean (screenshots)? Thank you! |
February 25, 2014 at 8:26 pm #347375 | |
thomasC-4 |
You define a text somewhere, I don't know where it would fit best Then you could use a shortcode in your post/pag like: And it would pick the correct language automatically. Best regards, |
February 26, 2014 at 8:13 am #347586 | |
sarah.n Supporter
Languages: English (English ) German (Deutsch ) |
Thank you for getting back to me Thomas, I hope I understood you correctly. If I did not please forgive me and correct me where necessary. You will need to register such a shortcode yourself where you will define the string you want to output. It will look like something like this: /** * Register string shortcode * * Usage in Post/Page content: * default: [wpml-get-string string="my-string-id"] */ function wpml_return_string($atts){ global $OPTION; extract(shortcode_atts(array( "string" => '1' ), $atts)); switch($string){ case '1': $output = __('String 1','your-theme-text-domain'); break; case '2': $output = __('String 2','your-theme-text-domain'); break; case '3': $output = __('String 3','your-theme-text-domain'); break; } return $output; } add_shortcode("wpml-get-string", "wpml_return_string"); Now when you scan your theme all the strings you will define in the shortcode will be registered under String Translation where you will be able to translate them. Them when you call the shortcode in your post/page content you only need to define the number of the string you want to output. Let me know how you get on with this. |
February 26, 2014 at 9:49 am #347665 | |
Andrey Supporter Timezone: Europe/Kiev (GMT+02:00) |
Dear Thomas, Please try Sarah's suggestion and let us know if we can be of further help. Thanks, |
March 5, 2014 at 2:08 pm #352691 | |
thomasC-4 |
Hi Sarah, Thanks for your answer. I placed the code into functions.php but the strings were not displayed in String Translations. The reason is probably that I could not register a text domain. How do I do that? Best regards, |
March 5, 2014 at 3:15 pm #352758 | |
sarah.n Supporter
Languages: English (English ) German (Deutsch ) |
Thank you for getting back to me Thomas. I would first check if your theme already registers a text domain. You can do this by searching inside your theme's template files for this function: "load_theme_textdomain" (without the quotes) In case it does not then you can find information on how to register a textdomain for your theme here: http://codex.wordpress.org/Function_Reference/load_theme_textdomain In case you are still not sure let us know and Andrey will enable the private info option so you can share with us temp access details to your site for further assistance. |
March 5, 2014 at 3:54 pm #352793 | |
thomasC-4 |
I just tried adding this code to functions.php add_action('after_setup_theme', 'crucial_setup'); function crucial_setup(){ and I even created the 'languages' folder as a subfolder to my theme folder. I think we should go for the private info option... |
March 6, 2014 at 9:21 am #353286 | |
Andrey Supporter Timezone: Europe/Kiev (GMT+02:00) |
Dear Thomas, We need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it. Thanks, |
March 11, 2014 at 10:25 am #356461 | |
thomasC-4 |
Thanks for your help. I don't have a test installation for this site but I have made a backup. Good luck |
March 11, 2014 at 2:42 pm #356743 | |
sarah.n Supporter
Languages: English (English ) German (Deutsch ) |
Hello Thomas, Thank you for getting back to us. I checked your site and you did quite well. All that was missing was to scan the theme for strings under "Theme and Plugins Localization". I did this for you and as you can see now under String Translation: /wp-admin/admin.php?page=wpml-string-translation/menu/string-translation.php&context=theme travelwaxer&status=0 the 3 strings you entered in your theme's functions.php file are there registered for translation. All you have to do now is actually translate them 🙂 |
March 11, 2014 at 3:38 pm #356784 | |
Andrey Supporter Timezone: Europe/Kiev (GMT+02:00) |
Dear Thomas, Please check this. Thanks, |
March 12, 2014 at 6:48 am #357167 | |
thomasC-4 |
Hi again, thanks for your help. I can now see the strings in String translations, but unfortuanately I cannot see any of my translations when I add the shortcode (I just see "String 1") [wpml-get-string string="1"] You can try putting it in this post for instance: hidden link By the way, I cannot find where you do the theme scanning? Best regards, |
March 12, 2014 at 8:51 am #357279 | |
sarah.n Supporter
Languages: English (English ) German (Deutsch ) |
Thomas, As I mentioned in my previous comment, scanning the theme is done under "Theme and plugins localization" - see here: /wp-admin/admin.php?page=sitepress-multilingual-cms/menu/theme-localization.php The translation should display as long as the strings are actually translated under "String Translation" - see here: hidden link Currently, non of those strings are actually translated. - see attached screenshot. P.S At some point (and especially if you are still having problems), you will want to update to the latest WPML versions. Both the core WPML plugins as well as its add-ons will need to be update. |