WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 22 months ago

#21691 closed defect (bug) (invalid)

WPLANG not settable in multisite if there are no language files

Reported by: foxinni Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Multisite Keywords: close
Focuses: Cc:

Description

I got a plugin running on a multisite and there is definitely something up with the translation.

I tracked the problem down to the WPLANG option in http://localhost/<subsite>/wp-admin/options.php being empty. I tried to update it, but it keeps reverting to blank. So down the line the issue with get_locale() looking for the WPLANG value in the site_options and then defaulting back to en_US because it's not picking it up from the wp-config.php defined WPLANG.

I'm assuming that the defined WPLANG in the wp-config.php does not apply in multisite instances. The plugin is only enabled on the separate blog instance, and I changed the translation in wp-config.php after the install if that has anything to do with it.

Simple filter to force the locale in the plugin for the moment:

function modify_locale(){
    return 'de_DE';
}
add_filter('locale','modify_locale');

I hope someone can reproduce this issue.

Attachments (1)

wplang-duh.diff (454 bytes) - added by wonderboymusic 3 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 @thee173 years ago

WPLANG in the wp-config.php is supposed to globally set the WPLANG for all sites on the install.

comment:2 @wonderboymusic3 years ago

You have to set language for each site individually in Network Admin - WPLANG in wp-config only works for site #1

comment:3 @foxinni3 years ago

I'm logged in as the super admin and then go to that site's settings, but it's not saving the WPLANG like I'm expecting it too. The interface is also not very intuitive in that regard. http://foxinni.com/screens/site-settings-20120827-112529.png. Is this behavior normal? Am I looking/editing in the wrong place?

comment:4 @wonderboymusic3 years ago

In sanitize_option():

case 'WPLANG':
	$allowed = get_available_languages();
	if ( ! in_array( $value, $allowed ) && ! empty( $value ) )
		$value = get_option( $option );
	break;

In get_available_languages():

/**
 * Get all available languages based on the presence of *.mo files in a given directory. The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory in which to search for language files. The default directory is WP_LANG_DIR.
 * @return array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.
 */
function get_available_languages( $dir = null ) {
	$languages = array();

	foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) {
		$lang_file = basename($lang_file, '.mo');
		if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
			0 !== strpos( $lang_file, 'admin-' ))
			$languages[] = $lang_file;
	}

	return $languages;
}

Do you have proper *.mo files for the languages you want?
Are they being loaded properly?

Version 0, edited 3 years ago by wonderboymusic (next)

@wonderboymusic3 years ago

comment:5 @wonderboymusic3 years ago

  • Keywords has-patch added

comment:6 follow-up: @SergeyBiryukov3 years ago

  • Keywords reporter-feedback added

Replying to foxinni:

So down the line the issue with get_locale() looking for the WPLANG value in the site_options and then defaulting back to en_US because it's not picking it up from the wp-config.php defined WPLANG.

If an empty WPLANG value exists, that's intentional, per ticket:18688:5.

The interface is also not very intuitive in that regard.

The proper screens for setting the language in Multisite are:

  1. For existing sites: My Sites → (Site Name) → Settings → General → Site Language.
  2. For new sites and for the main site: Network Admin → Settings → Default Language.

I tried to update it, but it keeps reverting to blank.

Couldn't reproduce that. Setting WPLANG in all possible ways (via Sites → Edit Site → Settings on the main site, or Settings → General or wp-admin/options.php on a subsite) works fine on my install.

  1. Do you have *.mo files in wp-content/languages for the language you're trying to set?
  2. Have you tried disabling all plugins?

I think I've found a related bug though. WPLANG site option is not populated on network setup for localized packages: #21726.

Replying to wonderboymusic:

The value should be IN the array, not excluded - attached patch

The check was introduced in [18346] and appears to be correct. If the new value is not within the allowed languages, it's not updated.

comment:7 in reply to: ↑ 6 ; follow-up: @foxinni3 years ago

  • Summary changed from WPLANG not set in multisite to WPLANG not settable in multisite

@ SergeyBiryukov:

Remember that I'm not changing the language of my entire Wordpress, I just want to have translations for my plugin to work for small American and European spelling differences ( en_US & us_US for example). So there are no languages in my wp-content/languages folder, and thus no drop-down settings anywhere to change the locale for the network or subsite. I've seen them before and know that they exist. :)

Perhaps translating just a plugin without the entire WordPress along with IS illogical... but I wrote applied filter to fix the issue and I'm very happy with the route I've chosen to save myself from writing options to change text.

I tried to update the WPLANG option again, both on my machine and my colleuses' in the wp-admin/options.php, plus adding update_site_option('WPLANG', 'testing'); to my plugins root file and still nothing updates. It just remains blank...

comment:8 @SergeyBiryukov3 years ago

  • Keywords has-patch reporter-feedback removed

Currently, setting WPLANG via the UI or via update_site_option() only works if there are corresponding files in wp-content/languages.

I guess using the locale or gettext filter workaround makes sense in your case.

comment:9 in reply to: ↑ 7 @thee173 years ago

You may want to consider that if they are using European spelling that they would be likely using en_GB for the European spelling as en_GB is a maintained WordPress localization. Also European spelling is often used in Canada that has a Canadian English version I've been maintaining that uses en_CA.

comment:10 @SergeyBiryukov3 years ago

  • Summary changed from WPLANG not settable in multisite to WPLANG not settable in multisite if there are no language files

comment:11 @SergeyBiryukov3 years ago

  • Keywords close added

The inability to change WPLANG without having language files in wp-content/languages sounds like expected behaviour to me.

comment:12 @wonderboymusic22 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Sergey says close

Note: See TracTickets for help on using tickets.