changeset: 4361:20b8c35ce0fd67c1ef15011f58d55003778f5f4d
tag: tip
user: Aidan Kehoe <kehoea(a)parhasard.net>
date: Sun Dec 23 18:05:26 2007 +0100
files: lisp/ChangeLog.carbon2 lisp/mule/mule-cmds.el src/ChangeLog.carbon2
src/intl-carbon.c
description:
Use the carbon infrastructure to determine the language environment.
2007-12-23 Aidan Kehoe <kehoea(a)parhasard.net>
* intl-carbon.c:
Add #'carbon-current-locale, with the implementation taken from
Mozilla.
2007-12-23 Aidan Kehoe <kehoea(a)parhasard.net>
* mule/mule-cmds.el (init-locale-at-early-startup):
If #'carbon-current-locale is available, use it when determining
the language environment at startup.
diff -r b72bac98b78a7793c95dc2318e6e033c9f81769a -r
20b8c35ce0fd67c1ef15011f58d55003778f5f4d lisp/mule/mule-cmds.el
--- a/lisp/mule/mule-cmds.el Sun Dec 23 17:35:49 2007 +0100
+++ b/lisp/mule/mule-cmds.el Sun Dec 23 18:05:26 2007 +0100
@@ -1469,17 +1469,25 @@ of buffer-file-coding-system set by this
(declare-fboundp (mswindows-set-current-locale userdef)))
;; Unix:
(let (locstring)
- ;; Init the POSIX locale from the environment--this calls the C
- ;; library's setlocale(3).
- (set-current-locale "")
- ;; Can't let locstring be the result of (set-current-locale "")
- ;; because that can return a more detailed string than we know how
- ;; to handle.
- (setq locstring (current-locale)
- ;; assume C lib locale and LANG env var are set correctly.
- ;; use them to find the langenv.
- langenv
- (and locstring (get-language-environment-from-locale
+ (unless (and-fboundp
+ #'carbon-current-locale
+ ;; If Carbon provides us with the locale string, we want
+ ;; to use that, instead of the code that checks the
+ ;; C environment below.
+ (setq locstring
+ (carbon-current-locale)))
+ ;; Init the POSIX locale from the environment--this calls the C
+ ;; library's setlocale(3).
+ (set-current-locale "")
+ ;; Can't let locstring be the result of (set-current-locale "")
+ ;; because that can return a more detailed string than we know how
+ ;; to handle.
+ (setq locstring (current-locale)))
+
+ ;; assume C lib locale and LANG env var are set correctly.
+ ;; use them to find the langenv.
+ (setq langenv
+ (and locstring (get-language-environment-from-locale
locstring)))))
;; All systems:
(unless langenv (setq langenv "English"))
diff -r b72bac98b78a7793c95dc2318e6e033c9f81769a -r
20b8c35ce0fd67c1ef15011f58d55003778f5f4d src/ChangeLog.carbon2
--- a/src/ChangeLog.carbon2 Sun Dec 23 17:35:49 2007 +0100
+++ b/src/ChangeLog.carbon2 Sun Dec 23 18:05:26 2007 +0100
@@ -1,3 +1,9 @@ 2007-12-22 Aidan Kehoe <kehoea@parhasa
+2007-12-23 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * intl-carbon.c:
+ Add #'carbon-current-locale, with the implementation taken from
+ Mozilla.
+
2007-12-22 Aidan Kehoe <kehoea(a)parhasard.net>
* console-carbon-impl.h:
diff -r b72bac98b78a7793c95dc2318e6e033c9f81769a -r
20b8c35ce0fd67c1ef15011f58d55003778f5f4d src/intl-carbon.c
--- a/src/intl-carbon.c Sun Dec 23 17:35:49 2007 +0100
+++ b/src/intl-carbon.c Sun Dec 23 18:05:26 2007 +0100
@@ -20,12 +20,314 @@
#include <config.h>
#include "lisp.h"
+#include "text.h"
+
+#include <Carbon/Carbon.h>
+#include <ApplicationServices/ApplicationServices.h>
+
+Lisp_Object Vcarbon_current_language_unicode_set;
+
+#if !defined(__COREFOUNDATION_CFLOCALE__)
+typedef void* CFLocaleRef;
+#endif
+
+struct iso_lang_map
+{
+ Ascbyte* iso_code;
+ short mac_lang_code;
+ short mac_script_code;
+};
+
+typedef struct iso_lang_map iso_lang_map;
+
+iso_lang_map lang_list[] = {
+ { "sq", langAlbanian, smRoman },
+ { "am", langAmharic, smEthiopic },
+ { "ar", langArabic, smArabic },
+ { "hy", langArmenian, smArmenian},
+ { "as", langAssamese, smBengali },
+ { "ay", langAymara, smRoman},
+ { "eu", langBasque, smRoman},
+ { "bn", langBengali, smBengali },
+ { "dz", langDzongkha, smTibetan },
+ { "br", langBreton, smRoman },
+ { "bg", langBulgarian, smCyrillic },
+ { "my", langBurmese, smBurmese },
+ { "km", langKhmer, smKhmer },
+ { "ca", langCatalan, smRoman },
+ { "zh", langTradChinese, smTradChinese },
+ { "hr", langCroatian, smRoman },
+ { "cs", langCzech, smCentralEuroRoman },
+ { "da", langDanish, smRoman },
+ { "nl", langDutch, smRoman },
+ { "en", langEnglish, smRoman },
+ { "eo", langEsperanto, smRoman },
+ { "et", langEstonian, smCentralEuroRoman},
+ { "fo", langFaeroese, smRoman },
+ { "fa", langFarsi, smArabic },
+ { "fi", langFinnish, smRoman },
+ { "fr", langFrench, smRoman },
+ { "ka", langGeorgian, smGeorgian },
+ { "de", langGerman, smRoman },
+ { "el", langGreek, smGreek },
+ { "gn", langGuarani, smRoman },
+ { "gu", langGujarati, smGujarati },
+ { "he", langHebrew, smHebrew },
+ { "iw", langHebrew, smHebrew },
+ { "hu", langHungarian, smCentralEuroRoman },
+ { "is", langIcelandic, smRoman },
+ { "in", langIndonesian, smRoman },
+ { "id", langIndonesian, smRoman },
+ { "iu", langInuktitut, smEthiopic },
+ { "ga", langIrish, smRoman },
+ { "it", langItalian, smRoman },
+ { "ja", langJapanese, smJapanese },
+ { "jw", langJavaneseRom, smRoman },
+ { "kn", langKannada, smKannada },
+ { "ks", langKashmiri, smArabic },
+ { "kk", langKazakh, smCyrillic },
+ { "ky", langKirghiz, smCyrillic },
+ { "ko", langKorean, smKorean },
+ { "ku", langKurdish, smArabic },
+ { "lo", langLao, smLao },
+ { "la", langLatin, smRoman },
+ { "lv", langLatvian, smCentralEuroRoman },
+ { "lt", langLithuanian, smCentralEuroRoman },
+ { "mk", langMacedonian, smCyrillic },
+ { "mg", langMalagasy, smRoman },
+ { "ml", langMalayalam, smMalayalam },
+ { "mt", langMaltese, smRoman },
+ { "mr", langMarathi, smDevanagari },
+ { "mo", langMoldavian, smCyrillic },
+ { "ne", langNepali, smDevanagari },
+ { "no", langNorwegian, smRoman },
+ { "or", langOriya, smOriya },
+ { "om", langOromo, smEthiopic },
+ { "ps", langPashto, smArabic },
+ { "pl", langPolish, smCentralEuroRoman },
+ { "pt", langPortuguese, smRoman },
+ { "pa", langPunjabi, smGurmukhi },
+ { "ro", langRomanian, smRoman },
+ { "ru", langRussian, smCyrillic },
+ { "sa", langSanskrit, smDevanagari },
+ { "sr", langSerbian, smCyrillic },
+ { "sd", langSindhi, smArabic },
+ { "si", langSinhalese, smSinhalese },
+ { "sk", langSlovak, smCentralEuroRoman },
+ { "sl", langSlovenian, smRoman },
+ { "so", langSomali, smRoman },
+ { "es", langSpanish, smRoman },
+ { "su", langSundaneseRom, smRoman },
+ { "sw", langSwahili, smRoman },
+ { "sv", langSwedish, smRoman },
+ { "tl", langTagalog, smRoman },
+ { "tg", langTajiki, smCyrillic },
+ { "ta", langTamil, smTamil },
+ { "tt", langTatar, smCyrillic },
+ { "te", langTelugu, smTelugu },
+ { "th", langThai, smThai },
+ { "bo", langTibetan, smTibetan },
+ { "ti", langTigrinya, smEthiopic },
+ { "tr", langTurkish, smRoman },
+ { "tk", langTurkmen, smCyrillic },
+ { "ug", langUighur, smCyrillic },
+ { "uk", langUkrainian, smCyrillic },
+ { "ur", langUrdu, smArabic },
+ { "uz", langUzbek, smCyrillic },
+ { "vi", langVietnamese, smVietnamese },
+ { "cy", langWelsh, smRoman },
+ { "ji", langYiddish, smHebrew },
+ { "yi", langYiddish, smHebrew },
+ { NULL, 0, 0}
+};
+
+struct iso_country_map
+{
+ Ascbyte* iso_code;
+ short mac_region_code;
+};
+
+typedef struct iso_country_map iso_country_map;
+
+iso_country_map country_list[] = {
+ { "US", verUS},
+ { "EG", verArabic},
+ { "DZ", verArabic},
+ { "AU", verAustralia},
+ { "BE", verFrBelgium },
+ { "CA", verEngCanada },
+ { "CN", verChina },
+ { "HR", verYugoCroatian },
+ { "CY", verCyprus },
+ { "DK", verDenmark },
+ { "EE", verEstonia },
+ { "FI", verFinland },
+ { "FR", verFrance },
+ { "DE", verGermany },
+ { "EL", verGreece },
+ { "HU", verHungary },
+ { "IS", verIceland },
+ { "IN", verIndiaHindi},
+ { "IR", verIran },
+ { "IQ", verArabic },
+ { "IE", verIreland },
+ { "IL", verIsrael },
+ { "IT", verItaly },
+ { "JP", verJapan },
+ { "KP", verKorea },
+ { "LV", verLatvia },
+ { "LY", verArabic },
+ { "LT", verLithuania },
+ { "LU", verFrBelgiumLux },
+ { "MT", verMalta },
+ { "MA", verArabic },
+ { "NL", verNetherlands },
+ { "NO", verNorway },
+ { "PK", verPakistan },
+ { "PL", verPoland },
+ { "PT", verPortugal },
+ { "RU", verRussia },
+ { "SA", verArabic },
+ { "ES", verSpain },
+ { "SE", verSweden },
+ { "CH", verFrSwiss },
+ { "TW", verTaiwan},
+ { "TH", verThailand },
+ { "TN", verArabic},
+ { "TR", verTurkey },
+ { "GB", verBritain },
+ { NULL, 0 }
+};
+
+typedef CFLocaleRef (*fpCFLocaleCopyCurrent_type) (void);
+typedef CFStringRef (*fpCFLocaleGetIdentifier_type) (CFLocaleRef);
+
+static Ibyte *
+carbon_get_pseudo_posix_locale (short scriptCode, short langCode, short regionCode)
+{
+ int i;
+ Bytecount len;
+ int validResultFound = 0;
+ DECLARE_EISTRING (res);
+
+ /* parse language */
+ for (i=0; NULL != lang_list[i].iso_code; i++)
+ {
+ if (langCode == lang_list[i].mac_lang_code &&
+ scriptCode == lang_list[i].mac_script_code)
+ {
+ eicpy_ascii (res, lang_list[i].iso_code);
+ validResultFound = true;
+ break;
+ }
+ }
+
+ /* parse region */
+ for (i=0; NULL != country_list[i].iso_code; i++)
+ {
+ if (regionCode==country_list[i].mac_region_code)
+ {
+ eicat_ch (res, '-');
+ eicat_ascii (res, country_list[i].iso_code);
+ validResultFound = true;
+ break;
+ }
+ }
+
+ if (validResultFound)
+ {
+ len = eilen (res);
+ return eicpyout_malloc (res, &len);
+ }
+
+ return NULL;
+}
Lisp_Object Qcarbon_unicode;
+
+DEFUN ("carbon-current-locale", Fcarbon_current_locale, 0, 0, 0, /*
+Return the current OS X locale.
+
+This reflects the locale used by the Carbon programs on your system, and
+follows the POSIX format, that is, ab_BC, where ab is a language code and BC
+is a country code.
+*/
+ ())
+{
+ /* On MacOSX, the recommended way to get the user's current locale is to use
+ the CFLocale APIs. However, these are only available on 10.3 and later.
+ So for the older systems, we have to keep using the Script Manager APIs. */
+ static int checked = 0;
+ static fpCFLocaleCopyCurrent_type fpCFLocaleCopyCurrent = NULL;
+ static fpCFLocaleGetIdentifier_type fpCFLocaleGetIdentifier = NULL;
+ Lisp_Object res = Qnil;
+
+ if (!checked)
+ {
+ CFBundleRef bundle =
+ CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
+ if (bundle)
+ {
+ // We dynamically load these two functions and only use them if
+ // they are available (OS 10.3+).
+ fpCFLocaleCopyCurrent = (fpCFLocaleCopyCurrent_type)
+ CFBundleGetFunctionPointerForName(bundle,
+ CFSTR("CFLocaleCopyCurrent"));
+ fpCFLocaleGetIdentifier = (fpCFLocaleGetIdentifier_type)
+ CFBundleGetFunctionPointerForName(bundle,
+
CFSTR("CFLocaleGetIdentifier"));
+ }
+ checked = 1;
+ }
+
+ if (fpCFLocaleCopyCurrent)
+ {
+ // Get string representation of user's current locale
+ CFLocaleRef userLocaleRef = fpCFLocaleCopyCurrent();
+ CFStringRef userLocaleStr = fpCFLocaleGetIdentifier(userLocaleRef);
+ int size;
+ Extbyte *buf;
+
+ CFRetain(userLocaleStr);
+
+ size = CFStringGetLength(userLocaleStr);
+ size = (size + 1) * 2;
+ buf = alloca_extbytes (size);
+
+ if (!CFStringGetCString (userLocaleStr, (char *) buf, size,
+ kCFStringEncodingUnicode))
+ {
+ signal_error (Qtext_conversion_error,
+ "Error converting from Carbon text format for locale",
+ Qunbound);
+ }
+
+ res = make_ext_string (buf, size - 2, Qcarbon_unicode);
+
+ CFRelease(userLocaleStr);
+ CFRelease(userLocaleRef);
+ }
+ else
+ {
+ /* Legacy MacOSX locale code */
+ long script = GetScriptManagerVariable(smSysScript);
+ long lang = GetScriptVariable(smSystemScript,smScriptLang);
+ long region = GetScriptManagerVariable(smRegionCode);
+
+ Ibyte *text = carbon_get_pseudo_posix_locale((short)script, (short)lang,
+ (short)region);
+ if (text)
+ {
+ res = make_string (text, qxestrlen(text));
+ }
+ }
+ return res;
+}
void
syms_of_intl_carbon (void)
{
+ DEFSUBR (Fcarbon_current_locale);
DEFSYMBOL (Qcarbon_unicode);
}
diff -r b72bac98b78a7793c95dc2318e6e033c9f81769a -r
20b8c35ce0fd67c1ef15011f58d55003778f5f4d lisp/ChangeLog.carbon2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/ChangeLog.carbon2 Sun Dec 23 18:05:26 2007 +0100
@@ -0,0 +1,6 @@
+2007-12-23 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * mule/mule-cmds.el (init-locale-at-early-startup):
+ If #'carbon-current-locale is available, use it when determining
+ the language environment at startup.
+
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches