Locale setting error

Nextcloud version (eg, 20.0.5): 27.1.2.1
Operating system and version (eg, Ubuntu 20.04): Arch Linux x86_64
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.56 (Unix
PHP version (eg, 7.4): 8.2.4

Hello. It’s my first post so if I opened this topic on the wrong category, please move it to correct place.
I just downloaded “setup-nextcloud.php” and tried to install it. everything done but when I wanna run it (http://localhost) I face this error:

Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed.

Please install one of these locales on your system and restart your web server.

I just debug the code and modified this file: nexctloud/lib/private/legacy/OC_Util.php to this:

		if (!OC_Util::isSetLocaleWorking()) {			
			$errors[] = [
				'error' => $l->t('Setting locale to %s failed.',
					['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
						. 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']),
				'hint' => $l->t('Please install one of these locales on your system and restart your web server.')
			];
			echo locale_get_default(); // <-- this line	
		}

and after running localhost, the result is strange :slight_smile: sometimes it gives me en_US_POSIX and sometimes it gives me en_US. Although when I running locale on my terminal it gives me:

LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

Is this the first time you’ve seen this error? (Y/N): Yes

Steps to replicate it:

  1. running localhost

The output of your Nextcloud log in Admin > Logging:

I can't access it but there is no log in this file: nextclout/data/nextcloud.log

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):
here is nextcloud/config/config.php

<?php
$CONFIG = array (
  'instanceid' => 'ocg7uekkqofu',
);

Hello,

on my Ubuntu 22.04 locale says:

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

I never used Arch but en_US.utf8 isn’t the same string as en_US.UTF-8.

1 Like

Thank you dear @rakekniven for replying. First I thought the problem is this but I checked the code on nextclod/lib/private/legacy/OC_Util.php and checked the isNonUTF8Locale() function on line1023:

	private static function isNonUTF8Locale() {
		if (function_exists('escapeshellcmd')) {
			return '' === escapeshellcmd('§');
		} elseif (function_exists('escapeshellarg')) {
			return '\'\'' === escapeshellarg('§');
		} else {
			return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0));
		}
	}

as you know /i parameter means “case insensitive” in line return 0 === preg_match(‘/utf-?8/i’, setlocale(LC_CTYPE, 0)); so it seems the code shouldn’t make difference between “en_US.utf8” and “en_US.UTF8” but about your notice. Maybe you’re right but I changed the code to:

	private static function isNonUTF8Locale() {
		if (function_exists('escapeshellcmd')) {
			return '' === escapeshellcmd('§');
		} elseif (function_exists('escapeshellarg')) {
			return '\'\'' === escapeshellarg('§');
		} else {
			return 0 === preg_match('/utf8/i', setlocale(LC_CTYPE, 0)); // <-- I changed this line
		}
	}

and the problem still is there.

Thanks in advance

Maybe, but you’re also missing the dash after “utf”. Correct would be en_US.UTF-8

See here: Locale - ArchWiki

Thank you @bb77 for your reply.
At first view I thought too the problem is that you said but when please look at this command:

cat /etc/locale.conf | grep LANG=en_US.UTF-8
LANG=en_US.UTF-8

I also did run the command:

localectl set-locale LANG=en_US.UTF-8

so there shouldn’t be any problem. But after trying these steps I decided to ask my question here.
I should add when I run this command locale -a I get:

C
C.UTF-8
en_US.utf8
POSIX

So I think maybe the problem is about this section. because I randomly get en_US and en_US_POSIX so maybe this is the clue.
Anyway I keep debugging but I don’t know NextCloud so if you give me a clue, I will check it immediately.

Thanks in advance

Unfortunately the problem has been solved.
But why unfortunately? Because I couldn’t find what was the problem? I couldn’t find what happened and what was the reason this error?
I restart the web server and abruptly everything works great now.
I’m trying to replicate the problem to find out what happened and give a report here.

Thanks in advance the people read this topic and answered me.

Thank you all