5

I use OS X Yosemite.

When I run locale I get this:

locale 
LANG= 
LC_COLLATE="C" 
LC_CTYPE="UTF-8" 
LC_MESSAGES="C" 
LC_MONETARY="C" 
LC_NUMERIC="C" 
LC_TIME="C" 
LC_ALL=

Question

Is the emptiness of LANG and LC_ALL bad/normal/prefered?

Normally, I wouldn't care that much about it, but I've got a warning

(process:16182): Gtk-WARNING **: Locale not supported by C library.
        Using the fallback 'C' locale.

when I was using GTK (here's a link to my previous quesiton on this).

People have been struggling with this problem in many languages (Python for example) and different OS (Ubuntu for example).

The point is I couldn't find any solution for C language and OS X.

Community
  • 1
  • 1
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79

1 Answers1

5

I would guess that the GTK warning is because GTK is actually trying to use the Mac language and locale settings from System Preferences to make a locale identifier string, using that string with setlocale(), and being told that the C library doesn't support that locale. As a result, it's defaulting to the "C" locale. If it weren't trying to find a better locale, there would be little reason to warn that it's using the "C" locale because that's what would be expected when LANG and LC_ALL are unset.

OS X has support for many languages and locales in the high-level frameworks (Cocoa, etc.), but not all of those are also supported at the level of the C library. What are the language and locale settings in System Preferences? What locale identifier would you expect for your language and locale? See if that's in the output from locale -a (or, similarly, if there's a directory for it in /usr/share/locale).

Another thing to check is Terminal's preferences. On the Settings pane, under the Advanced tab, is "Set locale environment variables on startup" set? If not, then those environment variables won't be set by default, which might explain what you're seeing. If the setting is enabled but you're still not getting those environment variables, that suggests that Terminal was not able to find a suitable C-library locale that matches your system settings.

Finally, you can simply try setting LANG to what you want to use. For example:

export LANG=pl_PL.UTF-8
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • 1. I'm setting locale inside my C program - maybe this is the issue? 2. Could you please tell me if I should set those environmental variables or not? I mean, is it a bug? Or there's just no point in setting these variables on OS X? – Mateusz Piotrowski Jun 14 '15 at 18:45
  • 1
    Did you set the C library locale using `setlocale()`? Or did you set the environment variables, in which case which variables did you set? What did you set it to? Was it one of the locale identifiers listed by `locale -a`? If you used `setlocale()`, what did it return? Is your program expected to be run from a shell (e.g. in Terminal) or is it a GUI app that will be launched from the Finder, Dock, etc.? Setting the C library locale does have an effect on OS X, assuming the locale identifier is one that's known to the library. It would presumably also affect GTK. – Ken Thomases Jun 14 '15 at 19:32
  • Excuse me, if made a mistake. I did not use `setlocale()`. I just use `g_locale_from_utf8()`. A here might be a problem. Since locale is not set, then it is using the C locale. My program has GTK GUI. Adding `setlocale(LC_ALL, "pl_PL.UTF-8");` hasn't changed anything - the warning is still popping up. – Mateusz Piotrowski Jun 14 '15 at 22:27
  • 1
    First, when you launch a GUI app from the Mac GUI (Finder, Dock, etc.), it gets a completely different set of environment variables than programs run in the shell get. In general, neither `LANG` nor any of the `LC_*` variables will be set for a GUI app. However, calling `setlocale(LC_ALL, "pl_PL.UTF-8")` early enough should work. Did you call it before GTK initialized? You could try running your app from a shell after setting `LC_ALL` in the environment, to see if that makes a difference (e.g. `LC_ALL=pl_PL.UTF-8 /path/to/YourApp.app/Contents/MacOS/YourApp`). – Ken Thomases Jun 14 '15 at 23:47
  • **1.** Sorry for a big misunderstanding here - my app has a GTK GUI but I always run it from the terminal. I'm call `setlocale(LC_ALL, "pl_PL.UTF-8")` as the first function in the `int main()` - it doesn't help however. **2.** I've run `export LC_ALL=pl_PL.UTF-8` and now I've got *pl_PL.UTF-8* in every `LC_*` :D. Additionally, **the warning disappeared!** Nevertheless, I wonder if I accidentally broke something with `export LC_ALL=pl_PL.UTF-8`? **3.** I don't know what to do with this command you've posted: `LC_ALL=pl_PL.UTF-8 /path/to/YourApp.app/Contents/MacOS/YourApp` – Mateusz Piotrowski Jun 15 '15 at 20:30
  • 1
    OK. Does `pl_PL.UTF-8` match your settings for language and region in System Preferences? Did you check the Terminal preference setting I mentioned? Terminal ought to be setting that automatically. It won't break anything. I'm not sure why your call to `setlocale()` isn't helping. That may be a GTK issue where it overrides it with its own call after yours. The command I suggested (your item 3) was just a way of testing running your app with the `LC_ALL` environment set to `pl_PL.UTF-8` for that command only (as opposed to exporting it, which affects all subsequent commands in that shell). – Ken Thomases Jun 15 '15 at 22:01
  • 1. In System Preferences -> Language and Region: [I've got English as a primary language and Polish is listed as the second language](https://imgur.com/U9TCLTS). 2. Terminal: I've got "*Set locale environment variables on startup*" enabled. 3. I've run `LC_ALL=pl_PL.UTF-8 /path/to/app` command and it did show any warning. – Mateusz Piotrowski Jun 17 '15 at 10:04
  • 2
    I'm guessing the Region in System Preferences is Poland. The locale `pl_PL.UTF-8` is the Polish language in Poland using UTF-8 for character encoding. I use `en_US.UTF-8` for English language in the U.S. There's not going to be any C library locale defined for the English language in Poland (i.e. `en_PL.UTF-8`). That's why Terminal is not setting `LANG` for you in your shells, even though you have "Set locale environment variables on startup" enabled. There's no value it could set that would both work and correspond to your system settings. – Ken Thomases Jun 17 '15 at 12:30
  • 1
    Bull's eye :) . Now, that I've changed region to the UK and back to Poland, my `locale` shows: `LANG="en_GB.UTF-8"`. As a result, my app is no longer showing any warnings. Thank you! Now that I understand what's going on I can read about it on my own. – Mateusz Piotrowski Jun 17 '15 at 12:37