Skip Navigation

[Résolu] WPML translatable strings – how to use in Content Templates?

This support ticket is created Il y a 8 années et 8 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 7 réponses, has 2 voix.

Last updated by Alan Il y a 8 années et 1 mois.

Assigned support staff: Luo Yang.

Auteur
Publications
#279422
phone string.jpg

I am trying to modify a content template to work with WPML. Prior to installing WPML, my content template hard coded certain texts to appear before their corresponding data. E.g PHONE: [phone number]
I have edited the WPML string translator, so the system knows that "Phone" is "Ffôn" in Welsh.

Now I need the content template to display the appropriate version depending on which language the user has chosen.

I have tried to follow this page: https://toolset.com/documentation/multilingual-sites-with-types-and-views/ so I know that I need to insert a translatable string, and it will look something like this:

[wpml-string context="wpv-views"]Phone[/wpml-string]

When I'm in the WPML > String Translation, my "phone" field is listed as in the image I uploaded (phone string.jpg)

I am confused about what context to use, and what should go in between the wpml-string tags

[wpml-string context=   ?????   ]   ????? [/wpml-string]

Thanks very much.

#279678

The "context" attribute:
$context
(string) (required) Context information for the translators
Default: None
http://codex.wordpress.org/Function_Reference/_x

in your WP admin side, WPML-> String translation
you will see a dropdown menu:
Select strings within context:

the string been wrapped into shortcode [wpml-string], is the string you are going to translate.

#279871
field phone name.jpg

Thanks Luoy,

You've helped me with half of my query.

But I still don't know what needs to go in between the shortcodes.
This is what I've tried, but it doesn't work.

[wpml-string context= "plugin Types"]field phone name[/wpml-string]

As you can see, I have tried it with the name of the string as it appears in the String Translation list via WPML, which seems to appear as "field phone name" [see attached image].

However, when I test this in the content template (embedded in a view on a wordpress page), it just displays the text "field phone name" on the page, instead of the actual String ("Phone" in English, "Ffon" in Welsh).

I get the feeling I'm missing something really basic.
thanks again for your help.
Alan

#280081

Could you duplicate same problem in a test site, and fill below private detail box with login details,
Also point out the problem page URL, and View URL, I need test and debug in a live website

#280456

I tested in your website, put the shortcode
[wpml-string context= "plugin Types"]field phone name[/wpml-string]

Into the content template:
hidden link

Goto WPML-> String translation
search the key word "field phone name", and translate it into Welsh version "field phone name Welsh":
hidden link

See the result page:
English version:
hidden link
Welsh version:
hidden link

It works fine.

#280514
field names.jpg

Hi Luoy,

Thanks for your help with this.

I never wanted to translate the phrase "field phone name", I was simply using that because that's how it appears to be named when I first looked in WPML String Translation. This was already there (plus the other examples, screenshot)

Context = plugin Types
Name = field phone name
String = Phone (and the Welsh string = Ffon)

What I wanted was a way of displaying the String (not the Name).

What you've suggested results in a new string being created. When I now look in WPML string Translation, I see this new string there:

Context: plugin Types
Name: wpml-shortcode-a529a41bf5065e57d823995856415e65e
String = field phone name (and the translation, "field phone name Welsh")

From this, I can see a potential solution, which would be to simply create a brand new wpml-shortcode string called "Phone" and then translate that.
Is that the way it's supposed to work? It seems like duplication when the translated strings are already in the system.

Given that the original piece of data (the one called field phone name, at the top) already has the appropriate strings translated, I just wanted to use these strings as labels within my content template.
That's what I was expecting from the [wpml string] shortcode, as that seemed logical.
Have I just misunderstood, and perhaps it is necessary to create these new wpml shortcodes, rather than being able to use the ones that are already there?

Looking at that screenshot - I'm not sure how or when these were created, but have these somehow taken me down the wrong path?

#280811

Q: What I wanted was a way of displaying the String (not the Name).

As I mentioned above, you can try WPML shortcode wpml-string, like this
[wpml-string context= "my-context"] here put the string [/wpml-string]

More help:
https://toolset.com/documentation/multilingual-sites-with-types-and-views/

If you are going to display other string, please post the string here.
In the screenshot you mentioned above, I can see some different string, not sure what string are you going to translate.

Q: From this, I can see a potential solution, which would be to simply create a brand new wpml-shortcode string called "Phone" and then translate that.
Is that the way it's supposed to work? It seems like duplication when the translated strings are already in the system.

It is up to you, if you need translate "Phone", just register it into WPML system.
More help:
http://wpml.org/documentation/getting-started-guide/string-translation/

#322074

After some more playing with it, I finally understand how it works! thanks