How to change language file used by _e function

I am trying to make my own language switcher for my WordPress site. I am generating all labels using the _e and similar functions. So I am guessing the only thing I need to do is to change the locale used by WordPress. How can I do this programmatically? So in the ideal scenario when a user clicks on the desired language "this code" is run and WordPress uses the corresponding .mo file for the translation.
Category: Web

Changing static text in a theme into variable content that also respects language. Easiest way

I bought a Theme which unfortunately has some static content, I managed to hide and remove some via editing and the custom css. But I have a text field above the navigation where it says "Work Time" I need a way to write the German and English version of that text somewhere in my WP-Admin panel and tell the theme to load selected language text into that text field. I have coded some stuff in php js and mysql so …
Category: Web

How to get full native language instead of iso?

I am not using WPML or Polylang, but multisite to create multiple languages. The code below is used to make a language switcher, but I want a second menu with the full language name for a different menu (i.e. EN should be English, FR - Français, DE - Deutsch). Wordpress has the native names stored (because when selecting a language you get a list with the native language name), but how can I access this to use? $languages = get_available_languages(); …
Category: Web

WordPress Multisite for multi-language

I want to make a WordPress with multiple languages. I have two WordPress sites and I want them to use the same domain name. Site 1: http://example.com/en Site 2: http://example.com/de Is this possible? What information do I need to search for to find a tutorial. I don't want to use a plugin like WPML to translate content, I have to use multiple WordPress sites.
Category: Web

Translate custom post type and taxonomy slug in URL?

I need help how to translate the custom post type and taxonomy when using multisite and multi-language. I am using subdirectory a /en /sv etc. Are using the plugin (Multisite Language Switcher), but can not change the rewrite settings there. So I am guesing I have to change some rewrite? Or should I translate the post type with translations file, .mo .po? This is how the post type set up are in functions.php. Should I do something with the rewrite? …
Category: Web

Multiple languages menus problem

I'm trying to add language option to my website. I've coded my theme and I need to show the web in three different languages. I've got the little flags and I've managed to pass a php variable with the language it's selected. With that variable I've made a if for the wp_nav_menu assignment in the header.php. It works actually. When I change the language the correct menu in the correct language comes up. The problem is that when I hit …
Category: Web

Post and Page Inheritance to subsites in a WordPress Network

I have to develop a multi-country, multi-lingual website. One country may have multiple languages. I have setup a WordPress Network and created subsites for each country like following. abc.com/ > Global Website abc.com/usa > USA Website abc.com/fra > France Website I am detecting Countries through Geo Location API and forcefully redirect them to their own country's website. Each country has their own set of languages e.g. France will have English and French with French as default language. I decided to …
Category: Web

why is translation not working on theme?

Background I am using the theme Rookie from Sportpress. I created a child theme. Translation files are existing, especially german in my case. Wordpress is set to german language. The Problem Translation is working fine everywhere except on themes provided templates like the search results page content or pagination. Affected are the SRP title, nothing found page title and nothing found page content. They just stay in default english language. Pagination is affected too. The search form in the content …
Category: Web

get_categories only getting categories in the main language

I am trying to retrieve in the "content composer" the categories of projects based on the active language. But i only get the categories off the main language, never on the other. My code is: Category All $categories = get_categories('taxonomy=jw_portfolio_categories'); if(!empty($categories)){ foreach($categories as $cat){ ?><option value="<?php echo $cat->term_id; ?>"><?php echo $cat->name; ?></option><?php } } ?> </select> Any idea on how to get all the categories or the ones of the active language in the WP backoffice?
Category: Web

I have a plugin that applies a Google translation to my page--how does the browser know which language to display?

My site uses a plugin (Google Language Translator) to apply a Google translation of the text (see page here--the flags at the top of the page switch the language). If I change to another language, close the browser, re-open the browser, and re-open my page, the same language is displayed. How does the browser know to display in the same language as before? Is there some variable set somewhere? Perhaps a cookie, or session ID? Or perhaps some kind of …
Category: Web

How do I change a plugin language of only one page?

My WordPress blog is set up as nl_NL. This means that my bookly plugin is also displayed in nl_NL. In the Plugin directory there is a folder languages with loads of other languages. I have one page in three different languages nl_NL, de_DE, en_EN, on this page I would like the booking plugin to be displayed in the correct language. I changed the page language via page id from nl_NL to de_DE Via the function.php, but this had no effect. …
Category: Web

Translation for a text that is not printed on the screen

How can I enable the translation for a text that is not printed on the screen? I was recently implementing the translation to my plugin and everything worked as expected. But doing the tests I realized that I was missing something. There is a small piece of code in my plugin that creates terms based on a condition, but one of them is a text and I need it to be translated. how can I do? I understand that __ …
Category: Web

How to let users change site language?

I translated all my theme strings and saved in .po and .mo files. I tested the implementation and it works fine, however I'm not sure how to let users choose their own language. Are there any built-in functions to do this? How do I do it?
Category: Web

WPML language switcher for custom rewrite rules

I am making custom rewrite rules for categories in a dual-language project (german as main, english as second language). The urls look like this example.com/fliegen > shows archive.php for category fliegen example.com/en/aviation > shows archive.php for category aviation (the translated fliegen) This could be achieved by changing the category-base to . (although it doesn't seem to work in my case?) Unfortunately that wouldn't be enough for me, anyways; there is a custom taxonomy called filter in the game aswell, which …
Category: Web

Change WooCommerce currency programmatically on AJAX request

I am adding a custom ajax_action to fetch a product and display price html (same template as everywhere else on my page), the issue is that the price being returned is not equal to the current price set by user. In my AJAX call I have tried sending currency/wcmlc as a POST/GET parameter but this does not work. I have also tried different actions I could find online. I believe the problem is that the filter wcml_client_currency is not effective …
Category: Web

TinyMCE - Add button that changes direction of selected text

Ok, I am going to create website in Urdu(rtl) & English(ltr) language that contain paragraphs like this: <p style="direction:rtl">کیا حال ہے buddy? سب خیریت ہے؟</p> You can see that sentence in not showing correctly. I want to change the direction of English words in sentense. like this: <p style="direction:rtl">کیا حال ہے <bdo dir="ltr">buddy?</bdo> سب خیریت ہے؟</p> You can see more clear differance at JSfiddle. How it is possible? Any idea?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.