Add a locale in Mac OSX

后端 未结 3 1382
臣服心动
臣服心动 2020-12-30 01:16

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 firs

相关标签:
3条回答
  • 2020-12-30 01:52

    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.

    0 讨论(0)
  • 2020-12-30 01:56

    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.

    0 讨论(0)
  • 2020-12-30 01:59

    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 :)

    0 讨论(0)
提交回复
热议问题