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 4 replies, has 2 voices.

Last updated by Andreas W. 5 months, 2 weeks ago.

Assigned support staff: Andreas W..

Author Posts
April 30, 2019 at 1:30 pm #3711405

Joris Rijpma

I have made a custom template (theme/wpml/templates/language-switchers/template) which shows all languages in a dropdown.

Above this I want to show the current language.. How can I do this? I have the following code below:

<li class="dropdown">
<a class="dropdown-toggle" href="#" id="dropdown-lang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<< I WANT THE CURRENT LANGUAGE NAME HERE >>
</a>

<div class="dropdown-menu" aria-labelledby="dropdown-lang">
{% for code, language in languages %}
<a class="dropdown-item" href="{{ language.url }}">{{ language.native_name }}</a>
{% endfor %}
</div>

April 30, 2019 at 8:47 pm #3714867

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for contacting the WPML Support.

We do have a documentation for WPML language switcher in twig templates available here:

https://wpml.org/documentation/getting-started-guide/language-setup/designing-custom-language-switchers-using-template-files/

As you can see you can access the default language switcher options like current language and so on by creating a enhanced config.json file.

I hope this answers your question.

Kind regards
Andreas

May 1, 2019 at 7:47 am #3716719

Joris Rijpma

Hello Andreas,

I have seen the TWIG templates page, but that didn't help me.
With the following code I can see the current language code:

{{ current_language_code }} // which outputs 'en'

But I want to see the full name, like 'English'.

May 2, 2019 at 5:34 pm #3727827

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for your message.

You possbily will need to add a condition with the proper twig syntax:

Something like:

{% if current_language_code == 'en' %}
<p>English</p>
{% elseif current_language_code == 'fr' %}
<p>Francaise</p>
{% endif %}

I hope this answers your question and solves the issue. Let me know if you need any further assistance.

Kind regards
Andreas

May 2, 2019 at 5:36 pm #3727861

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Additional to my last email, please try to add a config.json file as this:

{
"name" : "ISO codes for menus",
"for": ["menus"],
"settings": {
"display_flags": 1,
"display_names_in_native_lang": 0,
"display_names_in_current_lang": 1
}
}

This should enable the options for flag and current language inside of the switcher options.

More information here:
https://wpml.org/documentation/getting-started-guide/language-setup/designing-custom-language-switchers-using-template-files/

Kind regards
Andreas