# Workaround to make C.UTF-8 the default locale?



## Spartrekus (May 13, 2019)

Hello,

A good method to make C.UTF-8 is to add  the settings of locales to ~/.shrc.

However, how to force that to be by default for all users? If they want to change this, they can populate their own ~/.shrc. 

There is a lot of asking for this, but it is often solved by locale user settings (.e.g. ~/.shrc).

Have fun and regards


----------



## zirias@ (May 13, 2019)

login.conf(5), see ENVIRONMENT.

e.g. add to the `default` entry in /etc/login.conf:

```
:lang=C.UTF-8:\
        :charset=UTF-8:
```
and don't forget to run cap_mkdb(1) on it.

You might want to set the variables in /etc/profile as well, so X sessions started from a display manager like `sddm` get them set too:

```
LANG=C.UTF-8; export LANG
CHARSET=UTF-8; export CHARSET
```


----------



## ThothK (May 21, 2019)

Hi Zirias,


Zirias said:


> You might want to set the variables in /etc/profile as well, so X sessions started from a display manager like `sddm` get them set too:
> 
> ```
> LANG=C.UTF-8; export LANG
> ...



To make sure I understand this correctly, X sessions starting from a display manager (slim in my case) will not use /etc/login.conf. I am guessing because no one is logged in. 
The duplication in /etc/profile is specifically for ... what?

What else relies on /etc/profile? The comments inside refer to /etc/login.conf.


thanks


=thoth=


----------



## Spartrekus (May 21, 2019)

ThothK said:


> Hi Zirias,
> 
> 
> To make sure I understand this correctly, X sessions starting from a display manager (slim in my case) will not use /etc/login.conf. I am guessing because no one is logged in.
> ...


Thank you ! Sounds interesting.

(note that I don't use X11, unless for web browser)


----------



## PMc (May 21, 2019)

Zirias said:


> login.conf(5), see ENVIRONMENT.
> 
> e.g. add to the `default` entry in /etc/login.conf:
> 
> ...



That `:charset` entry is happily copied along by everybody commenting on the issue, while it actually is just bogus, i.e. nothing seems to use it.



> You might want to set the variables in /etc/profile as well, so X sessions started from a display manager like `sddm` get them set too:
> 
> ```
> LANG=C.UTF-8; export LANG
> ...



An this one is even more bogus: there is no `CHARSET` variable concerned - what is set by the login.conf `:charset` entry is an `MM_CHARSET` variable (which doesnt seem to be used either).


----------



## PMc (May 21, 2019)

Some more problem and bogus:

I do not know if a construct like `C.UTF-8` is in any way legal. I doubt it - there is either simply `C`, or there is some country with UTF-8 - and if you don't want the country, you can always use `en_US.UTF-8`.
Setting `LANG` (or in login.conf `:lang`) has some side-effects which you may or may not want: aside from the character-set it does also influence the date&time-formats, decimal delimiters, monetary symbols, and whatever else. Further, it tries to provide translations for error messages (which are typically nonsense).
In order to avoid these, i.e. leave them in the default american mode which less likely breaks compatibilities, I found it best to leave the `LANG` (or `:lang`) variable alone and instead only set `LC_CTYPE=en_US.UTF-8` (or your preferred language) by adding this to the `:setenv` option in login.conf.



ThothK said:


> To make sure I understand this correctly, X sessions starting from a display manager (slim in my case) will not use /etc/login.conf.



This is the basic idea. The charset is a user-specific feature. Internally to the machine all is just bytes (`LANG=C`).
(Think it similar to the time setting: the timezone is a user-specific feature, while internally the machine just counts seconds.)

Therefore all daemons and server applications are by default using just bytes (`LANG=C`), and if they want something different, they have to care by themselves for that.
xdm(1) is a daemon/server in that regard.

Checking my system, it is indeed so that the `xdm` does not have environment, neither has the X server. Nevertheless the Window-Manager and all further clients get the LC_CTYPE, assumingly from login.conf, as I don't recall having it configured anywhere else.


----------



## ralphbsz (May 22, 2019)

And if you set it in /etc/profile, you need to think through whether it needs to be in the section only for interactive logins.  Do you really want to use this for non-interactive logins, commands coming in via ssh, batch, cron jobs?  Maybe you do, maybe you don't.


----------



## zirias@ (May 22, 2019)

ThothK said:


> The duplication in /etc/profile is specifically for ... what?
> 
> What else relies on /etc/profile?


/etc/profile is read by _bourne _shells when executed as a login shell. A session started by a display manager will typically be a bourne shell script, so /etc/profile is sourced and a good place to set some environment. Of course, if your user's shell is a bourne shell, you will have `LANG` set twice for a console login, but this doesn't hurt.


PMc said:


> That  :charset entry is happily copied along by everybody commenting on the issue, while it actually is just bogus, i.e. nothing seems to use it.


Maybe you're right on this, still it is used even in the example `russian` class in /etc/login.conf, so I just assume there is _some _software using it.


PMc said:


> what is set by the login.conf  :charset entry is an  MM_CHARSET variable


Indeed, I didn't read the manpage properly here.


PMc said:


> I do not know if a construct like  C.UTF-8 is in any way legal.


I don't either, but that was asked about. Still if such a thing is legal, it makes some sense: Use a "neutral" locale, but with UTF-8 charset (while your suggested `en_US.UTF-8` will use US-american date formats and so on).


PMc said:


> Setting  LANG (or in login.conf  :lang) has some side-effects which you may or may not want [...]


I'd say that's _exactly _what you want. But admittedly, `LANG` is a misnomer here, suggesting it would _only _set the language.


PMc said:


> In order to avoid these, i.e. leave them in the default american mode which less likely breaks compatibilities, [...]


Of course, any correctly written script relying on exact reproducible output of some tools should always set `LANG=C` in its environment.


PMc said:


> Therefore all daemons and server applications are by default using just bytes ( LANG=C), and if they want something different, they have to care by themselves for that.


I'd say that's only half true, all it takes using the standard C library is `setlocale(LC_ALL, "")` and some functions start to behave locale-specific (e.g. in `ctype.h`).


ralphbsz said:


> And if you set it in /etc/profile, you need to think through whether it needs to be in the section only for interactive logins. Do you really want to use this for non-interactive logins, commands coming in via ssh, batch, cron jobs? Maybe you do, maybe you don't.


AFAIK, /etc/profile should only be considered by login shells.


----------

