$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Adding Language Switcher in header , WP|Programmer puzzle solving
最新消息: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)

Adding Language Switcher in header , WP

matteradmin8PV0评论

Currently, I'm building multi languages blog. As I know, almost WP language translator plugins are based on .po & .mo files. here is a problem. A new language what I'm going to add does not exist with .po & .mo files, it's just a dialect(local) language.

That's why I defined in php and grab the language.php files as below code.

header.php

<a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=newlanguage"> New Language</a>
<a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=eng">English</a>

function.php

<?php session_start();
$_SESSION['language'] = $_GET['lang'];
if ( $_SESSION['language'] == 'newlanguage' ) {
require (TEMPLATEPATH .'/languages/new-language.php');
}
else {
require (TEMPLATEPATH .'/languages/english.php');  // default language
} ?>

the problem is it doesn't work, if I load to the new page, "new-language" is disappear and it automatically changes to the default language.

My question is Can someone guide me to the right way/codes with developer solution?

Currently, I'm building multi languages blog. As I know, almost WP language translator plugins are based on .po & .mo files. here is a problem. A new language what I'm going to add does not exist with .po & .mo files, it's just a dialect(local) language.

That's why I defined in php and grab the language.php files as below code.

header.php

<a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=newlanguage"> New Language</a>
<a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=eng">English</a>

function.php

<?php session_start();
$_SESSION['language'] = $_GET['lang'];
if ( $_SESSION['language'] == 'newlanguage' ) {
require (TEMPLATEPATH .'/languages/new-language.php');
}
else {
require (TEMPLATEPATH .'/languages/english.php');  // default language
} ?>

the problem is it doesn't work, if I load to the new page, "new-language" is disappear and it automatically changes to the default language.

My question is Can someone guide me to the right way/codes with developer solution?

Share Improve this question edited Feb 14, 2013 at 10:22 Eugene Manuilov 11.4k4 gold badges44 silver badges50 bronze badges asked Feb 14, 2013 at 10:19 RonaldRonald 1,0849 silver badges16 bronze badges 5
  • possible duplicate of How to update the language used by wordpress from a plugin – kaiser Commented Feb 14, 2013 at 13:32
  • Please take a look at this question. Your question was already asked and answered two times. – kaiser Commented Feb 14, 2013 at 13:32
  • If the .po file, and its correspondent .mo, don't exist, you have to create it yourself. – brasofilo Commented Feb 14, 2013 at 18:45
  • @ronaldtgi, please add your solution as an Answer. – brasofilo Commented Feb 23, 2013 at 10:35
  • Does this answer your question? How to update the language used by wordpress from a plugin – Gonçalo Peres Commented Apr 30, 2020 at 7:42
Add a comment  | 

2 Answers 2

Reset to default 0

http://wordpress/extend/plugins/wcm-user-language-switcher I tried wcm language switcher, it only supports for users, not for guest who are not logged in. anyway thanks to kaiser & brasofilo.

Finally, I got a solution with theme switcher plugin http://wordpress/extend/plugins/theme-switcher I duplicate my theme and keep one is default, then create next one for new-language. even it takes more space in hosting, it was definitely what I need.

just add to header.php as the follow codes <?php wp_theme_switcher(); ?> or <?php wp_theme_switcher('dropdown'); ?>

it allowed for all users,guests and also eveyone can switch without logging in. theme switcher plugin also provide for sidebar widget with dropdown & lists style.

Try https://wordpress/plugins/language-switcher/

Language Switcher allows you to map urls of alternative languages for Post Types and Taxonomies.

Additionally it allows you to filter archive pages by language.

It is a good option if your multi-language architecture includes different wordpress installations but it also works for centralized architecture with all the content under the same installation.

Post a comment

comment list (0)

  1. No comments so far