Can not change site language in Wordpress - wordpress

I'm trying to set the german language for the Wordpress backend.
German is also installed and can be selected under:
Settings> General> Site Language
Unfortunately it jumps back to English when saving.
My attempts so far:
The following did not work (for me):
wp_config.php WPLANG set and also removed
Looking at the database by setting, it is set to de_DE
Loco Translate installed and viewed. There, too, like the Site Language, it is output as English. Loco removed again. No WPML/Loco installed.
Checked for language updates, there were none.
Installed formal German and tried to select.
Language files controlled by FTP. Only German available, no EN.
Check latest Wordpress 5.8.
No Errors in Log Files
Test .htaccess, wp-content, wp-content/languages and all other subfolders of wp-content set to 777. Only for a sec. Really.
Deactive all Plugins
Other settings such as the time (UTC + 2) could be changed and saved
Activate all WordPress debug mode for developers. Nothing
define('FS_METHOD', 'direct'); doesnt help
Check WP site-health.
Browser-Language set to german
Try another Browser
The following did work:
Installed and activated a Wordpress original theme "Twenty One" as a test

Since only the theme change worked, it had to be due to the theme. So I scoured the files and found it here:
The code says, and this was confirmed to me by support when I asked, that if "Deactivate translations" is not active in the theme options, absolute is set to en_US.
function et_divi_maybe_change_frontend_locale( $locale ) {
$option_name = 'divi_disable_translations';
$theme_options = get_option( 'et_divi' );
$disable_translations = isset ( $theme_options[ $option_name ] ) ? $theme_options[ $option_name ] : false;
if ( 'on' === $disable_translations ) {
return 'en_US';
}
return $locale;
}
add_filter( 'locale', 'et_divi_maybe_change_frontend_locale' );

Related

htaccess redirect url without chaging url in address bar

Hello i am using WordPress with WP-globus which is a translation plugin. I have two languages selected English and french. The plugin adds '/fr/' to the end of the domain to load the french content.
For example:
xxxxxx refers to the post title.
mysite.com/xxxxxx displays english version
mysite.com/fr/xxxxxx - displays the french version
What i want is that when visitor go to mysite.fr/xxxxxx , it should load content of mysite.com/fr/xxxxxx.
Can anyone guide me with this. Can this be done using the htaccess?
Note: the url in address bar must not display mysite.com/fr/xxxxxx but must display mysite.fr/xxxxxx
I have fixed this issue, And working fine for me. Do some minor chnages in wpglobus plugin.
You have two different domains,both have pointing to same hosting right?
mysite.com
mysite.com.fr(load french content)
Here the solution,
Go to wpglobus plugin folder
inside the folder includes/class-wpglobus-config.php open and paste the following line after the mentioned line
public $extended_options = array(); after
protected $domain_french = 'mysite.com.fr'; //add this line only
Next Find this function init_current_language()
end of this function add this line
if( stristr( $_SERVER['HTTP_HOST'], $this->domain_french ) )
$this->language = 'fr';
Save the file.thats it.
Now your mysite.com.fr site loaded french content default.
Next you need to prevent adding /fr/ in french site.
same includes folder fine class-wpglobus-utils.php open it.
Find function localize_url
inside the function find this line
if ( ($language === $config->default_language && $config->hide_default_language))
to
if ( ($language === $config->default_language && $config->hide_default_language) || $language ==='fr')
thats it. I hope this solution solve your problem.

Can't Change Buddypress Language

I've tried too much for changing the language of buddypress but failed.
I have set the language in wp-config.php
define('WPLANG', 'es_ES');
if ( file_exists( WP_LANG_DIR . '/buddypress-es_ES.mo' ) ) {
load_textdomain( 'buddypress', WP_LANG_DIR . '/buddypress-es_ES.mo' );
}
Nothing worked. Please help.
That code should be good. Why the if statement when define('WPLANG', 'es_ES'); should work properly? BuddyPress follows the language settings set by WordPress.
Verify you have the translation file uploaded via:
wp-content/languages/themes/your_theme-es_ES.mo
Also, note that if you're using WordPress v4.0 and above you can change the language in the dashboard (assuming you have the language files) via Settings > General > Site Language.

Translate plugin and wordpress and the same time

I have seen many questions and answers but none that fit the bill. So here is my issue.
I have a plugin that I have localized which works fine on it's own when you add
define('WPLANG', 'my-plugin-name-de_DE');
to the wp-config file. But then when someone try's to translate the rest of the wp site it will not show the languange.
What am I missing here? I even tried naming the files I added the the wp-content folder to be the same name as my plugin... for example my-plugin-name-de_DE.po and .mo and no luck.
ANSWER
Ok so in wordpress 4.0 you can now select your language from the settings /general page.
My plugin was localized using the code
function plugin_action_init()
{
// Localization
load_plugin_textdomain('my-plugin-name', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
// Add actions
add_action('init', 'plugin_action_init');
Example of a string that would get translated.
_e('Simple text example', 'my-plugin-name');
SO all that needed to be done to get my plugin's and wordpress's translation to work at the same time was to upload the wp language that I want to the wp-content/languages folder. Making sure the file name was simply de_DE.mo and de_DE.po
Such a simple mistake :)

change frontend language wordpress

I am trying to change my theme language in the frontend from english to german . I have changed also wp-config.php file . But it doesn't work. I am using wordpress 4.0
Can some one what should to do change language?
You can do the following:
Get the the language pack (e.g. de_DE.mo) from wordpress.org. If the language pack isn't available as a standalone download, you could also use the .mo file which is bundled in the WordPress ZIP-file for your language. Located under wp-content/languages.
Move the .mo file to wp-content/languages/ of your default (english) WordPress installation.
Change the WPLANG constant in wp-config.php to the new locale (e.g. de_DE)
In your functions.php add the following filter:
functions.php
add_filter('locale', 'wpse27056_setLocale');
function wpse27056_setLocale($locale) {
if ( is_admin() ) {
return 'en_US';
}
return $locale;
}
Reference - https://wordpress.stackexchange.com/questions/27056/different-language-for-frontend-and-backend
Take a look at WordPress Codex - Translating WordPress
Additionally you can use WP plugins especially for translating your WP website:
Codestyling Localization
User Language Switch
Setup your site in the desired language in the admin settings and then download this plugin. In it you can setup the language for your admin backend side only ;)
http://wordpress.org/extend/plugins/kau-boys-backend-localization/
You can use the google translate plugin for wordpress. For more info see the plugin page.
Google Translate WordPress » WP Translate
I wanted to change the language in the front-end and keep the language in the backend the same. I tried using adding a filter to in function.php but that didn't work for me. What did was using a plugin - Backend localization
Change Language of Woocomerce through Functions Or change language of wodpress
/* ==== Function Start ==== */
add_filter('gettext', 'translate_reply44');
add_filter('ngettext', 'translate_reply44');
function translate_reply44($translated) {
$translated = str_ireplace('Undo?', 'numaları sipariş silindi. Sepete geri almak istiyorsanız tıklayın? ', $translated);
return $translated;
}
/* ==== Function END ==== */
Since 4.7, you should do the following:
function wp_noshor_redefine_locale($locale) {
if( is_admin() ):
switch_to_locale('en_US');
endif;
}
add_filter('init','wp_noshor_redefine_locale');
this changes the dashbaord to English while setting front-end to the language you choose from the setting option.

How to customize Wordpress Theme before going live

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.

Resources