Template strings translation

Hi guys,

I’m working on a multilingual site using WPML and wonder what’s the most simple method to translate L&L templates having hard coded strings.

Do i need to duplicate the template for each language and translate the strings manually?

Thanks for your leads if someone already worked in this context.

I can still check if the URL contains the language key:

<If check="{Url current}" includes value="/en/">See the CV<Else />Voir le CV</If>

Not sure it’s solid rock.

I sometimes do this with an ACF options page which can then be translated with WPML, with text fields for each string, pulled into templates using the from=options attribute like <Field string_author_prefix from=options />

I’ve also done it for simpler sites with the WordPress user locale meta, though WPML doesn’t really interact with this meta unfortunately:

<Switch check="{User locale}">
  <When value="de_DE" />
  <Set string_author_prefix>von </Set>
  <When />
  <Set string_author_prefix>by </Set>
1 Like

Hi @julia,

Thank you for the hint.
I guess User locale returns the language from the user’s browser, not necessarily the one set by WPML?

We could also get WPML language using a shortcode:

But it’s more work than checking the language key in the URL, provided this is how WPML is set for URLs obviously.

You should check how WPML saves the laguage. In Polylang I can call a taxonomy called language with L&L and get the current language. Maybe WPML uses the same approach.

If thats the case, you can set a variable with the value from the taxonomy an use switch (See Julias post) to build the labels. At least with Polylang this works like a charm.

And a check for the path (like you suggested) can be used as fallback for the rare case you load something before the language is defined from WPML. (I had one case with DIVI where this was neccessary)

Yes, there is this shortcode to get the current language in WPML as mentioned above:

function get_language_shortcode() {
    return apply_filters( 'wpml_current_language', null );
add_shortcode( 'language', 'get_language_shortcode' );

Right, probably more robust than checking the URL:

<Set currentLang><Shortcode language /></Set>

<Switch check="{Get currentLang}">
  <When value="en" />
    <Set string_cv> See the CV</Set>
  <When />
    <Set string_cv>Voir le CV</Set>

Thanks guys!