最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

multi language - Localisation and Wordpress

matteradmin51PV0评论

So I'm setting up translations for a website based on locale. But it seems like Wordpress is determining this with the language as set in the Admin.

How do I set up a localisation so that if I'm in Italy (or my computer is set to Italian) I get the it_IT.po and if I'm in England I get gb_UK etc etc (I have four languages).

And how do I test this? I want to test it by switching my browsers. I have a redirect to the language page using;

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteCond %{QUERY_STRING} !(^|&)lang=it [NC]
RewriteRule ^$ / [L,R=302]

But I want to using .po files for translating front end strings.

And I don't want a plugin but maybe I need to know what the plugins do.

So I'm setting up translations for a website based on locale. But it seems like Wordpress is determining this with the language as set in the Admin.

How do I set up a localisation so that if I'm in Italy (or my computer is set to Italian) I get the it_IT.po and if I'm in England I get gb_UK etc etc (I have four languages).

And how do I test this? I want to test it by switching my browsers. I have a redirect to the language page using;

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteCond %{QUERY_STRING} !(^|&)lang=it [NC]
RewriteRule ^$ http://example/it/ [L,R=302]

But I want to using .po files for translating front end strings.

And I don't want a plugin but maybe I need to know what the plugins do.

Share Improve this question asked Oct 10, 2018 at 17:12 Chris PinkChris Pink 7511 gold badge6 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

WordPress has no ability to switch language based on URL or query string parameter. In fact it does no dynamic language switching at all. Wherever you've seen this working, it would have been using a plugin.

You say you don't want to use a plugin, which means you'll have to write all the switching logic yourself. It's possible using the locale filter, but I'd recommend you look for a plugin to do this for you.

Alternatively set up WordPress multisite with a site for Italian and a site for English. You can use your directory paths like /it/ for this.

As a side point - be careful with locale codes. gb_UK is not valid. British English would be en_GB. (language_REGION)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far