Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a locale in Mac OSX

Tags:

macos

locale

I'm using gettext in a MAMP environment. I have locale files for es_ES, ca_ES, en_US and gl_ES. No problem with the first three, but for the forth, I get an error when trying to bind the locale translations files to the gl_ES language (galician in Spain). This is not a problem with apache or PHP because the others work (and in my CentOS server I have the gl_ES package and works fine)

So I realize my Mac OS X version 10.6.8 came without Galician support. That's strange because it has support to Spanish, Catalan and Euskera, the other three official languages in Spain. Some terminal to show you:

$ locale -a | grep _ES
ca_ES
ca_ES.ISO8859-1
ca_ES.ISO8859-15
ca_ES.UTF-8
es_ES
es_ES.ISO8859-1
es_ES.ISO8859-15
es_ES.UTF-8
eu_ES
eu_ES.ISO8859-1
eu_ES.ISO8859-15
eu_ES.UTF-8
$ ll /usr/share/locale/ | grep _ES
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 ca_ES/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 ca_ES.ISO8859-1/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 ca_ES.ISO8859-15/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 ca_ES.UTF-8/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 es_ES/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 es_ES.ISO8859-1/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 es_ES.ISO8859-15/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 es_ES.UTF-8/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 eu_ES/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 eu_ES.ISO8859-1/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 eu_ES.ISO8859-15/
drwxr-xr-x   8 root  wheel   272B  3 dic  2010 eu_ES.UTF-8/

Regression

  • I tried the installation disks (adding language packs) but no success: they're just translations of the operating system.
  • I found this similar question, but doesn't have as much information and no good answers.
  • I came to localedef as an option, but it seems to be just for creating the .UTF-8 or similar when you already have the base file.

I have no clue on how to add galician support (or any other) to Mac OS X.

How to add a new locale in Mac OS X?

like image 576
Natxet Avatar asked Apr 03 '12 10:04

Natxet


3 Answers

After literally hours of searching, pouring over perl code, and head-scratching, I have concluded at Apple is epically failing in the locale-creation-and-definition department. Here's the deal: OSX gives you a (*ehem* ...shoddy) utility script written in perl located at /usr/bin/localedef, which is SUPPOSED to create a new locale. The manpage says that usage should be something like this (run inside of usr/share/locale):

localedef -i base_file -f UTF-8 new_locale_name

As stated by the OP, this command is just for copying a current locale. Well, I couldn't even get THAT to work! I don't know perl, but I found at least one careless code error in /usr/bin/localedef (line 512 references a sub called set_escape_char which should really be set_escape) and on top of that I couldn't get localedef to work at all so that's out. As stated by @alombarte you can just copy a current locale directory with cp -R src_locale trg_locale but he forgot to mention that there are differences between the source and target locales you need to actually manually change the text files within the new locale dir.

For example, I wanted to create the locale es_NI.UTF-8 (Nicaragua), with the correct currency code and monetary info, so here's what i did:

cd /usr/share/locale
sudo cp -R es_MX.UTF-8 es_NI.UTF-8
sudo vim es_NI.UTF-8/LC_MONETARY
# changed MXN to NIO, $ to C$, etc...
# saved LC_MONETARY

You may need to change other pertinent values depending on your use of the new locale. Here is the best collection of locale info I have been able to find online. If I were a better programmer I'd make a script that takes that websites "glibc" exported format and reformats it to work with the localedef command in Mac OSX.

P.S. apologies to @alombarte for the initial downvote... even though his response does not answer the true question, I didn't realize that it would be so incredibly difficult to do it any other way.

like image 87
AndyPerlitch Avatar answered Oct 29 '22 18:10

AndyPerlitch


This should do the trick:

cd /usr/share/locale
sudo cp -R es_ES gl_ES

Then open a new terminal session and list the locales again. Galician should be there :)

like image 21
alo Avatar answered Oct 29 '22 17:10

alo


Looking into this found that, as of Mac OS X 10.10.3, collation is still broken for Spanish and most European languages. Collation definitions for these locales are linked to an ASCII definition. This ends up breaking things such as ORDER BY clauses on PostgreSQL.

like image 30
Adrian M. Avatar answered Oct 29 '22 19:10

Adrian M.