mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add localization/language domain and locale support
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7910 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
db5766ea99
commit
110cd21262
22 changed files with 1042 additions and 169 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2000-10-27 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Added localization support
|
||||
* configure.in: Look for locale.h
|
||||
* Resources: New directory, files for languages.
|
||||
* Headers/gnustep/base/NSUserDefaults.h: Add missing localization
|
||||
keys.
|
||||
* Source/GSLocale.m: New functions for dealing with locales.
|
||||
* Source/NSUserDefaults.m (-_unlocalizedDefaults): New method.
|
||||
(-sharedUserDefaults): Set up Language domain.
|
||||
(-userLanguages): Create our own defaults, if necessary, to avoid
|
||||
recursion with sharedUserDefaults.
|
||||
(__createStandardSearchList): Put NSGlobalDomain before Language
|
||||
domain to match MacOSX docs (wasn't specified in OpenStep docs).
|
||||
|
||||
* Tools/locale_alias.m: New test-tool mostly for maintainance use.
|
||||
|
||||
2000-10-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSData.m: When deserialising selectors, register new
|
||||
|
|
|
@ -17,6 +17,70 @@
|
|||
<declared>Foundation/NSUserDefaults.h</declared>
|
||||
<conform>NSObject</conform>
|
||||
<desc>
|
||||
<p>
|
||||
NSUserDefaults provides an interface to the defaults system,
|
||||
which allows an application access to global and/or application
|
||||
specific defualts set by the user. A particular instance of
|
||||
NSUserDefaults, standardUserDefaults, is provided as a
|
||||
convenience. Most of the information described below
|
||||
pertains to the standardUserDefaults. It is unlikely
|
||||
that you would want to instantiate your own userDefaults
|
||||
object, since it would not be set up in the same way as the
|
||||
standardUserDefaults.
|
||||
</p>
|
||||
<p>
|
||||
Defaults are managed based on <em>domains</em>. Certain
|
||||
domains, such as <code>NSGlobalDomain</code>, are
|
||||
persistant. These domains have defaults that are stored
|
||||
externally. Other domains are volitale. The defaults in
|
||||
these domains remain in effect only during the existance of
|
||||
the application and may in fact be different for
|
||||
applications running at the same time. When asking for a
|
||||
default value from standardUserDefaults, NSUserDefaults
|
||||
looks through the various domains in a particular order.
|
||||
</p>
|
||||
<deflist>
|
||||
<term><code>NSArgumentDomain</code></term>
|
||||
<desc>
|
||||
Contains defaults read from the arguments provided to
|
||||
the application at startup. Volitile.
|
||||
</desc>
|
||||
<term>Application (name of the current process)</term>
|
||||
<desc>
|
||||
Application specific defaults, such as window positions. Persistant.
|
||||
</desc>
|
||||
<term><code>NSGlobalDomain</code></term>
|
||||
<desc>
|
||||
Global defaults. Persistant.
|
||||
</desc>
|
||||
<term>Language (name based on users's language)</term>
|
||||
<desc>
|
||||
Constants that help with localization to the users's
|
||||
language. Volitle
|
||||
</desc>
|
||||
<term><code>NSRegistrationDomain</code></term>
|
||||
<desc>
|
||||
Temporary defaults set up by the application. Volitile.
|
||||
</desc>
|
||||
</deflist>
|
||||
<p>
|
||||
The <em>Languages</em> default value is used to set up the
|
||||
constants for localization. GNUstep will also look for the
|
||||
<code>LANGUAGES</code> environment variable if it is not set
|
||||
in the defaults system. If it exists, it consists of an
|
||||
array of languages that the user prefers. At least one of
|
||||
the languages should have a corresponding localization file
|
||||
(typically located in the <file>Languages</file> directory
|
||||
of the GNUstep resources).
|
||||
</p>
|
||||
<p>
|
||||
As a special extension, on systems that support locales
|
||||
(e.g. GNU/Linux and Solaris), GNUstep will use information
|
||||
from the user specified locale, if the <em>Languages</em>
|
||||
default value is not found. Typically the locale is
|
||||
specified in the environment with the <code>LANG</code>
|
||||
environment variable.
|
||||
</p>
|
||||
</desc>
|
||||
<method type="NSUserDefaults*" factory="yes">
|
||||
<sel>standardUserDefaults</sel>
|
||||
|
|
|
@ -21,6 +21,79 @@
|
|||
</p>
|
||||
<hr>
|
||||
|
||||
<p>
|
||||
|
||||
NSUserDefaults provides an interface to the defaults system,
|
||||
which allows an application access to global and/or application
|
||||
specific defualts set by the user. A particular instance of
|
||||
NSUserDefaults, standardUserDefaults, is provided as a
|
||||
convenience. Most of the information described below
|
||||
pertains to the standardUserDefaults. It is unlikely
|
||||
that you would want to instantiate your own userDefaults
|
||||
object, since it would not be set up in the same way as the
|
||||
standardUserDefaults.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
Defaults are managed based on <em>domains</em>. Certain
|
||||
domains, such as <code>NSGlobalDomain</code>, are
|
||||
persistant. These domains have defaults that are stored
|
||||
externally. Other domains are volitale. The defaults in
|
||||
these domains remain in effect only during the existance of
|
||||
the application and may in fact be different for
|
||||
applications running at the same time. When asking for a
|
||||
default value from standardUserDefaults, NSUserDefaults
|
||||
looks through the various domains in a particular order.
|
||||
</p>
|
||||
|
||||
<dl>
|
||||
<dt><code>NSArgumentDomain</code>
|
||||
<dd>
|
||||
Contains defaults read from the arguments provided to
|
||||
the application at startup. Volitile.
|
||||
|
||||
<dt>Application (name of the current process)
|
||||
<dd>
|
||||
Application specific defaults, such as window positions. Persistant.
|
||||
|
||||
<dt><code>NSGlobalDomain</code>
|
||||
<dd>
|
||||
Global defaults. Persistant.
|
||||
|
||||
<dt>Language (name based on users's language)
|
||||
<dd>
|
||||
Constants that help with localization to the users's
|
||||
language. Volitle
|
||||
|
||||
<dt><code>NSRegistrationDomain</code>
|
||||
<dd>
|
||||
Temporary defaults set up by the application. Volitile.
|
||||
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
|
||||
The <em>Languages</em> default value is used to set up the
|
||||
constants for localization. GNUstep will also look for the
|
||||
<code>LANGUAGES</code> environment variable if it is not set
|
||||
in the defaults system. If it exists, it consists of an
|
||||
array of languages that the user prefers. At least one of
|
||||
the languages should have a corresponding localization file
|
||||
(typically located in the <file>Languages</file> directory
|
||||
of the GNUstep resources).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
As a special extension, on systems that support locales
|
||||
(e.g. GNU/Linux and Solaris), GNUstep will use information
|
||||
from the user specified locale, if the <em>Languages</em>
|
||||
default value is not found. Typically the locale is
|
||||
specified in the environment with the <code>LANG</code>
|
||||
environment variable.
|
||||
</p>
|
||||
|
||||
|
||||
<h2>Instance Variables </h2>
|
||||
<ul>
|
||||
|
|
|
@ -36,7 +36,7 @@ PACKAGE_NAME = gstep-base
|
|||
#
|
||||
# The list of subproject directories
|
||||
#
|
||||
SUBPROJECTS = Source Tools NSCharacterSets NSTimeZones
|
||||
SUBPROJECTS = Source Tools NSCharacterSets NSTimeZones Resources
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
|
|
39
Headers/gnustep/base/GSLocale.h
Normal file
39
Headers/gnustep/base/GSLocale.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* GSLocale - various functions for localization
|
||||
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Created: Oct 2000
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __GSLocale_H_
|
||||
#define __GSLocale_H_
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
@class NSDictionary;
|
||||
|
||||
GS_EXPORT NSString *GSSetLocale(NSString *locale);
|
||||
|
||||
GS_EXPORT NSDictionary *GSDomainFromDefaultLocale(void);
|
||||
|
||||
GS_EXPORT NSString *GSLanguageFromLocale(NSString *locale);
|
||||
|
||||
#endif
|
||||
|
|
@ -53,6 +53,7 @@ GS_EXPORT NSString* const NSMonthNameArray;
|
|||
GS_EXPORT NSString* const NSShortMonthNameArray;
|
||||
GS_EXPORT NSString* const NSTimeFormatString;
|
||||
GS_EXPORT NSString* const NSDateFormatString;
|
||||
GS_EXPORT NSString* const NSShortDateFormatString;
|
||||
GS_EXPORT NSString* const NSTimeDateFormatString;
|
||||
GS_EXPORT NSString* const NSShortTimeDateFormatString;
|
||||
GS_EXPORT NSString* const NSCurrencySymbol;
|
||||
|
@ -73,6 +74,13 @@ GS_EXPORT NSString* const NSNextDayDesignations;
|
|||
GS_EXPORT NSString* const NSNextNextDayDesignations;
|
||||
GS_EXPORT NSString* const NSPriorDayDesignations;
|
||||
GS_EXPORT NSString* const NSDateTimeOrdering;
|
||||
|
||||
GS_EXPORT NSString* const NSLanguageName;
|
||||
GS_EXPORT NSString* const NSLanguageCode;
|
||||
GS_EXPORT NSString* const NSFormalName;
|
||||
#ifndef NO_GNUSTEP
|
||||
GS_EXPORT NSString* const NSLocale;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* General implementation notes:
|
||||
|
|
|
@ -144,6 +144,9 @@
|
|||
/* Define if you have the <libxml/xmlversion.h> header file. */
|
||||
#undef HAVE_LIBXML_XMLVERSION_H
|
||||
|
||||
/* Define if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
|
|
45
Resources/GNUmakefile
Normal file
45
Resources/GNUmakefile
Normal file
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# Resources makefile for GNUstep Base Library
|
||||
# Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Adam Fedor <fedor@doc.com>
|
||||
# Date: Oct 2000
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
resourcedir = $(GNUSTEP_RESOURCES)
|
||||
languagedir = $(GNUSTEP_RESOURCES)/Languages
|
||||
|
||||
LANGUAGES = \
|
||||
Languages/English \
|
||||
Languages/German
|
||||
|
||||
LANGUAGE_INSTALL_FILES = $(LANGUAGES) Languages/Locale.aliases
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
# We don't actually build anything in this directory so
|
||||
# just include the common makefile rules
|
||||
include $(GNUSTEP_MAKEFILES)/rules.make
|
||||
|
||||
-include GNUmakefile.postamble
|
68
Resources/GNUmakefile.postamble
Normal file
68
Resources/GNUmakefile.postamble
Normal file
|
@ -0,0 +1,68 @@
|
|||
#
|
||||
# GNUmakefile.postamble
|
||||
#
|
||||
# Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written: Adam Fedor <fedor@gnu.org>
|
||||
# Date: Oct 2000
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
before-install::
|
||||
$(MKDIRS) $(languagedir)
|
||||
|
||||
# Things to do after installing
|
||||
after-install::
|
||||
for file in $(LANGUAGE_INSTALL_FILES); do \
|
||||
$(INSTALL_DATA) $$file $(resourcedir)/$$file ; \
|
||||
done
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
after-uninstall::
|
||||
for file in $(LANGUAGE_INSTALL_FILES); do \
|
||||
rm -f $(resourcedir)/$$file ; \
|
||||
done
|
||||
-rmdir $(languagedir)
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
37
Resources/Languages/English
Normal file
37
Resources/Languages/English
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* English */
|
||||
{
|
||||
NSLanguageName = "English";
|
||||
NSLanguageCode = ENG;
|
||||
NSFormalName = "English";
|
||||
|
||||
NSCurrencySymbol = "$";
|
||||
NSPositiveCurrencyFormatString = "$9,999.00";
|
||||
NSNegativeCurrencyFormatString = "$-9,999.00";
|
||||
NSInternationalCurrencyString = "$";
|
||||
|
||||
NSDecimalDigits = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
NSDecimalSeparator = ".";
|
||||
NSThousandsSeparator = ",";
|
||||
|
||||
NSAMPMDesignation = (AM, PM);
|
||||
NSDateFormatString = "%A, %B %d, %Y";
|
||||
NSDateTimeOrdering = DMYH;
|
||||
NSEarlierTimeDesignations = (prior, last, past, ago);
|
||||
NSHourNameDesignations = ((0, midnight), (12, noon, lunch), (10, morning), (14, afternoon), (19, dinner));
|
||||
NSLaterTimeDesignations = (next);
|
||||
NSMonthNameArray = (January, February, March, April, May, June, July, August, September, October, November, December);
|
||||
NSNextDayDesignations = (tomorrow);
|
||||
NSNextNextDayDesignations = (nextday);
|
||||
NSPriorDayDesignations = (yesterday);
|
||||
NSShortDateFormatString = "%d/%m/%Y";
|
||||
NSShortMonthNameArray = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
|
||||
NSShortTimeDateFormatString = "%d %b, %Y %H:%M";
|
||||
NSShortWeekDayNameArray = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
|
||||
NSThisDayDesignations = (today);
|
||||
NSTimeDateFormatString = "%a %b %d %H:%M:%S %z %Y";
|
||||
NSTimeFormatString = "%H:%M:%S";
|
||||
NSWeekDayNameArray = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
|
||||
NSYearMonthWeekDesignations = (year, month, week);
|
||||
}
|
||||
|
||||
|
33
Resources/Languages/German
Normal file
33
Resources/Languages/German
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* German */
|
||||
{
|
||||
NSLanguageName = "German";
|
||||
NSFormalName = "Deutsch";
|
||||
NSLanguageCode = "DEU";
|
||||
NSParentContext = "Default";
|
||||
|
||||
NSCurrencySymbol = "DM";
|
||||
NSDateFormatString = "%A, %B %d, %Y";
|
||||
NSDateTimeOrdering = DMYH; /* resolve numbers in Day,Month,Year,Hour order */
|
||||
NSDecimalDigits = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
NSDecimalSeparator = ",";
|
||||
NSEarlierTimeDesignations = (vor, letzten, letzte, vorige, vorherige, davor);
|
||||
NSHourNameDesignations = ((0, Mitternacht), (12, Mittag, mittags), (10, morgens), (14, nachmittags), (19, abends));
|
||||
NSInternationalCurrencyString = DEM; /* ISO 4217 */
|
||||
NSLaterTimeDesignations = ("später");
|
||||
NSMonthNameArray = (Januar, Februar, "März", April, Mai, Juni, Juli, August, September, Oktober, November, Dezember);
|
||||
NSNextDayDesignations = (morgen);
|
||||
NSNextNextDayDesignations = ("nächsten Tag"); /* (as in: am nächsten Tag) */
|
||||
NSPriorDayDesignations = (gestern);
|
||||
NSShortDateFormatString = "%d.%m.%Y"; /* "07.12.95" for example */
|
||||
NSShortMonthNameArray = (Jan, Feb, Mrz, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez);
|
||||
NSShortTimeDateFormatString = "%d.%b.%Y %H:%M"; /* "07. Dez. 95 16:50 " for example */
|
||||
NSShortWeekDayNameArray = (So, Mo, Di, Mi, Do, Fr, Sa);
|
||||
NSThisDayDesignations = (heute);
|
||||
NSThousandsSeparator = ".";
|
||||
NSTimeDateFormatString = "%a %b %d %Y %H:%M:%S %Z";
|
||||
NSTimeFormatString = "%H:%M:%S";
|
||||
NSWeekDayNameArray = (Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag);
|
||||
NSYearMonthWeekDesignations = (Jahr, Monat, Woche);
|
||||
NSPositiveCurrencyFormatString = "9,999.00$";
|
||||
NSNegativeCurrencyFormatString = "-9,999.00$";
|
||||
}
|
82
Resources/Languages/Locale.aliases
Normal file
82
Resources/Languages/Locale.aliases
Normal file
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
cs = Czech;
|
||||
da = Danish;
|
||||
da_DK = DenmarkDanish;
|
||||
de = German;
|
||||
de_AT = AustriaGerman;
|
||||
de_BE = BelgiumGerman;
|
||||
de_CH = SwitzerlandGerman;
|
||||
de_LU = LuxemburgGerman;
|
||||
el = Greek;
|
||||
el_GR = GreeceGreek;
|
||||
en = English;
|
||||
en_AU = AustraliaEnglish;
|
||||
en_CA = CanadaEnglish;
|
||||
en_DK = DenmarkEnglish;
|
||||
en_GB = BritainEnglish;
|
||||
en_IE = IrelandEnglish;
|
||||
en_NZ = NewZealandEnglish;
|
||||
en_US = AmericanEnglish;
|
||||
en_ZA = SouthAfricaEnglish;
|
||||
es = Spanish;
|
||||
es_AR = ArgentinaSpanish;
|
||||
es_BO = BoliviaSpanish;
|
||||
es_CL = ChileSpanish;
|
||||
es_CO = ColombiaSpanish;
|
||||
es_DO = DominicanRepublicSpanish;
|
||||
es_EC = EquadorSpanish;
|
||||
es_GT = GuatemalaSpanish;
|
||||
es_HN = HondurasSpanish;
|
||||
es_MX = MexicoSpanish;
|
||||
es_PA = PanamaSpanish;
|
||||
es_PE = PeruSpanish;
|
||||
es_PY = ParaguaySpanish;
|
||||
es_SV = ElSalvadorSpanish;
|
||||
es_US = USASpanish;
|
||||
es_UY = UruguaySpanish;
|
||||
es_VE = VenezuelaSpanish;
|
||||
et = Estonian;
|
||||
et_EE = EstoniaEstonian;
|
||||
eu = Basque;
|
||||
eu_ES = SpainBasque;
|
||||
fi = Finnish;
|
||||
fo = Faroese;
|
||||
fr = French;
|
||||
fr_BE = BelgiumFrench;
|
||||
fr_CA = CanadaFrench;
|
||||
fr_CH = SwitzerlandFrench;
|
||||
fr_LU = LuxemburgFrench;
|
||||
ga = Irish;
|
||||
he = Hebrew;
|
||||
hr = Croatian;
|
||||
hu = Hungarian;
|
||||
id = Indonesian;
|
||||
in = Indonesian;
|
||||
is = Icelandic;
|
||||
it = Italian;
|
||||
it_CH = SwitzerlandItalian;
|
||||
iw = Hebrew;
|
||||
ja = Japanese;
|
||||
kl = Greenlandic;
|
||||
lt = Lithuanian;
|
||||
lv = Latvian;
|
||||
nl = Dutch;
|
||||
nl_BE = BelgiumDutch;
|
||||
nl_NL = NetherlandsDutch;
|
||||
no = Norwegian;
|
||||
pl = Polish;
|
||||
pt = Portuguese;
|
||||
pt_BR = BrasilPortuguese;
|
||||
ro = Romanian;
|
||||
ru = Russian;
|
||||
ru_UA = UkraineRussian;
|
||||
sk = Slovak;
|
||||
sl = Slovenian;
|
||||
sr = Serbian;
|
||||
sv = Swedish;
|
||||
sv_FI = FinlandSwedish;
|
||||
th = Thai;
|
||||
tr = Turkish;
|
||||
uk = Ukrainian;
|
||||
zh = Chinese;
|
||||
}
|
|
@ -70,6 +70,7 @@ FILE_AUTHORS = \
|
|||
|
||||
GNU_MFILES = \
|
||||
GSCompatibility.m \
|
||||
GSLocale.m \
|
||||
Unicode.m \
|
||||
behavior.m \
|
||||
o_array.m \
|
||||
|
@ -117,6 +118,7 @@ libgnustep-base.def
|
|||
|
||||
GNU_HEADERS = \
|
||||
fast.x \
|
||||
GSLocale.h \
|
||||
GSUnion.h \
|
||||
GSIArray.h \
|
||||
GSIMap.h \
|
||||
|
|
196
Source/GSLocale.m
Normal file
196
Source/GSLocale.m
Normal file
|
@ -0,0 +1,196 @@
|
|||
/* GSLocale - various functions for localization
|
||||
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Created: Oct 2000
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <base/GSLocale.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
|
||||
#include <locale.h>
|
||||
#include <langinfo.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
|
||||
/* Set the locale for libc functions from the supplied string or from
|
||||
the environment if not specified. This function should be called
|
||||
as soon as possible after the start of the program. Passing
|
||||
@"" will set the locale from the environment varialbes LC_ALL or LANG (or
|
||||
whatever is specified by setlocale) Passing nil will just return the
|
||||
current locale. */
|
||||
NSString *
|
||||
GSSetLocale(NSString *locale)
|
||||
{
|
||||
const char *clocale;
|
||||
|
||||
clocale = NULL;
|
||||
if (locale)
|
||||
clocale = [locale cString];
|
||||
clocale = setlocale(LC_ALL, clocale);
|
||||
|
||||
if (clocale == NULL || strcmp(clocale, "C") == 0
|
||||
|| strcmp(clocale, "POSIX") == 0)
|
||||
clocale = NULL;
|
||||
|
||||
locale = nil;
|
||||
if (clocale)
|
||||
locale = [NSString stringWithCString: clocale];
|
||||
return locale;
|
||||
}
|
||||
|
||||
#define GSLanginfo(value) [NSString stringWithCString: nl_langinfo (value)]
|
||||
|
||||
/* Creates a locale dictionary from information provided by i18n functions.
|
||||
Many, but not all, of the keys are filled in or inferred from the
|
||||
available information */
|
||||
NSDictionary *
|
||||
GSDomainFromDefaultLocale(void)
|
||||
{
|
||||
int i;
|
||||
struct lconv *lconv;
|
||||
NSMutableDictionary *dict;
|
||||
NSMutableArray *arr;
|
||||
NSString *str1, *str2;
|
||||
|
||||
/* Time/Date Information */
|
||||
dict = [NSMutableDictionary dictionary];
|
||||
arr = [NSMutableArray arrayWithCapacity: 7];
|
||||
for (i = 0; i < 7; i++)
|
||||
[arr addObject: GSLanginfo(DAY_1+i)];
|
||||
[dict setObject: arr forKey: NSWeekDayNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 7];
|
||||
for (i = 0; i < 7; i++)
|
||||
[arr addObject: GSLanginfo(ABDAY_1+i)];
|
||||
[dict setObject: arr forKey: NSShortWeekDayNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 12];
|
||||
for (i = 0; i < 12; i++)
|
||||
[arr addObject: GSLanginfo(MON_1+i)];
|
||||
[dict setObject: arr forKey: NSMonthNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 12];
|
||||
for (i = 0; i < 12; i++)
|
||||
[arr addObject: GSLanginfo(ABMON_1+i)];
|
||||
[dict setObject: arr forKey: NSShortMonthNameArray];
|
||||
|
||||
str1 = GSLanginfo(AM_STR);
|
||||
str2 = GSLanginfo(PM_STR);
|
||||
if (str1 && str2)
|
||||
[dict setObject: [NSArray arrayWithObjects: str1, str2, nil]
|
||||
forKey: NSAMPMDesignation];
|
||||
|
||||
[dict setObject: GSLanginfo(D_T_FMT) forKey: NSTimeDateFormatString];
|
||||
[dict setObject: GSLanginfo(D_FMT) forKey: NSShortDateFormatString];
|
||||
[dict setObject: GSLanginfo(T_FMT) forKey: NSTimeFormatString];
|
||||
|
||||
lconv = localeconv();
|
||||
|
||||
/* Currency Information */
|
||||
if (lconv->currency_symbol)
|
||||
[dict setObject: [NSString stringWithCString: lconv->currency_symbol ]
|
||||
forKey: NSCurrencySymbol];
|
||||
if (lconv->int_curr_symbol)
|
||||
[dict setObject: [NSString stringWithCString: lconv->int_curr_symbol]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
if (lconv->mon_decimal_point)
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_decimal_point]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
if (lconv->mon_thousands_sep)
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_thousands_sep]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
/* FIXME: Get currency format from localeconv */
|
||||
|
||||
|
||||
/* Miscellaneous */
|
||||
if (nl_langinfo(YESSTR))
|
||||
[dict setObject: GSLanginfo(YESSTR) forKey: @"NSYesStr"];
|
||||
if (nl_langinfo(NOSTR))
|
||||
[dict setObject: GSLanginfo(NOSTR) forKey: @"NSNoStr"];
|
||||
|
||||
str1 = [NSString stringWithCString: setlocale(LC_ALL, NULL)];
|
||||
[dict setObject: str1 forKey: NSLocale];
|
||||
str2 = GSLanguageFromLocale(str1);
|
||||
if (str2)
|
||||
[dict setObject: str2 forKey: NSLanguageName];
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
NSString *
|
||||
GSLanguageFromLocale(NSString *locale)
|
||||
{
|
||||
NSString *language = nil;
|
||||
NSString *aliases = nil;
|
||||
|
||||
if (locale == nil)
|
||||
return @"English";
|
||||
|
||||
aliases = [NSBundle pathForGNUstepResource: @"Locale"
|
||||
ofType: @"aliases"
|
||||
inDirectory: @"Resources/Languages"];
|
||||
if (aliases)
|
||||
{
|
||||
NSDictionary *dict;
|
||||
dict = [NSDictionary dictionaryWithContentsOfFile: aliases];
|
||||
language = [dict objectForKey: locale];
|
||||
if (language == nil && [locale pathExtension])
|
||||
{
|
||||
locale = [locale stringByDeletingPathExtension];
|
||||
language = [dict objectForKey: locale];
|
||||
}
|
||||
if (language == nil)
|
||||
{
|
||||
locale = [locale substringFromRange: NSMakeRange(0, 2)];
|
||||
language = [dict objectForKey: locale];
|
||||
}
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
#else /* HAVE_LOCALE_H */
|
||||
NSString *
|
||||
GSSetLocale(NSString *locale)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSDictionary *
|
||||
GSDomainFromDefaultLocale(void)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *
|
||||
GSLanguageFromLocale(NSString *locale)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_LOCALE_H */
|
||||
|
||||
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ static inline int getDigits(const char *from, char *to, int limit)
|
|||
{
|
||||
if (source[sourceIdx] != format[formatIdx])
|
||||
{
|
||||
NSLog(@"Expected literal '%c' but gmtt '%c'",
|
||||
NSLog(@"Expected literal '%c' but got '%c'",
|
||||
format[formatIdx], source[sourceIdx]);
|
||||
}
|
||||
sourceIdx++;
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSDistributedLock.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <base/GSLocale.h>
|
||||
|
||||
/* Wait for access */
|
||||
#define _MAX_COUNT 5 /* Max 10 sec. */
|
||||
|
@ -76,6 +78,7 @@ static Class NSStringClass;
|
|||
*************************************************************************/
|
||||
static NSUserDefaults *sharedDefaults = nil;
|
||||
static NSMutableString *processName = nil;
|
||||
static NSMutableArray *userLanguages = nil;
|
||||
|
||||
/*************************************************************************
|
||||
*** Getting the Shared Instance
|
||||
|
@ -103,6 +106,109 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
DESTROY(sharedDefaults);
|
||||
}
|
||||
|
||||
/* Create a locale dictionary when we have absolutely no information
|
||||
about the locale. This method should go away, since it will never
|
||||
be called in a properly installed system. */
|
||||
+ (NSDictionary *) _unlocalizedDefaults
|
||||
{
|
||||
NSDictionary *registrationDefaults;
|
||||
NSArray *ampm;
|
||||
NSArray *long_day;
|
||||
NSArray *long_month;
|
||||
NSArray *short_day;
|
||||
NSArray *short_month;
|
||||
NSArray *earlyt;
|
||||
NSArray *latert;
|
||||
NSArray *hour_names;
|
||||
NSArray *ymw_names;
|
||||
|
||||
ampm = [NSArray arrayWithObjects: @"AM", @"PM", nil];
|
||||
short_month = [NSArray arrayWithObjects:
|
||||
@"Jan",
|
||||
@"Feb",
|
||||
@"Mar",
|
||||
@"Apr",
|
||||
@"May",
|
||||
@"Jun",
|
||||
@"Jul",
|
||||
@"Aug",
|
||||
@"Sep",
|
||||
@"Oct",
|
||||
@"Nov",
|
||||
@"Dec",
|
||||
nil];
|
||||
long_month = [NSArray arrayWithObjects:
|
||||
@"January",
|
||||
@"February",
|
||||
@"March",
|
||||
@"April",
|
||||
@"May",
|
||||
@"June",
|
||||
@"July",
|
||||
@"August",
|
||||
@"September",
|
||||
@"October",
|
||||
@"November",
|
||||
@"December",
|
||||
nil];
|
||||
short_day = [NSArray arrayWithObjects:
|
||||
@"Sun",
|
||||
@"Mon",
|
||||
@"Tue",
|
||||
@"Wed",
|
||||
@"Thu",
|
||||
@"Fri",
|
||||
@"Sat",
|
||||
nil];
|
||||
long_day = [NSArray arrayWithObjects:
|
||||
@"Sunday",
|
||||
@"Monday",
|
||||
@"Tuesday",
|
||||
@"Wednesday",
|
||||
@"Thursday",
|
||||
@"Friday",
|
||||
@"Saturday",
|
||||
nil];
|
||||
earlyt = [NSArray arrayWithObjects:
|
||||
@"prior",
|
||||
@"last",
|
||||
@"past",
|
||||
@"ago",
|
||||
nil];
|
||||
latert = [NSArray arrayWithObjects:
|
||||
@"next",
|
||||
nil];
|
||||
ymw_names = [NSArray arrayWithObjects:
|
||||
@"year",
|
||||
@"month",
|
||||
@"week",
|
||||
nil];
|
||||
hour_names = [NSArray arrayWithObjects:
|
||||
[NSArray arrayWithObjects: @"0", @"midnight", nil],
|
||||
[NSArray arrayWithObjects: @"12", @"noon", @"lunch", nil],
|
||||
[NSArray arrayWithObjects: @"10", @"morning", nil],
|
||||
[NSArray arrayWithObjects: @"14", @"afternoon", nil],
|
||||
[NSArray arrayWithObjects: @"19", @"dinner", nil],
|
||||
nil];
|
||||
registrationDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
ampm, NSAMPMDesignation,
|
||||
long_month, NSMonthNameArray,
|
||||
long_day, NSWeekDayNameArray,
|
||||
short_month, NSShortMonthNameArray,
|
||||
short_day, NSShortWeekDayNameArray,
|
||||
@"DMYH", NSDateTimeOrdering,
|
||||
@"tomorrow", NSNextDayDesignations,
|
||||
@"nextday", NSNextNextDayDesignations,
|
||||
@"yesterday", NSPriorDayDesignations,
|
||||
@"today", NSThisDayDesignations,
|
||||
earlyt, NSEarlierTimeDesignations,
|
||||
latert, NSLaterTimeDesignations,
|
||||
hour_names, NSHourNameDesignations,
|
||||
ymw_names, NSYearMonthWeekDesignations,
|
||||
nil];
|
||||
return registrationDefaults;
|
||||
}
|
||||
|
||||
+ (NSUserDefaults*) standardUserDefaults
|
||||
/*
|
||||
Returns the shared defaults object. If it doesn't exist yet, it's
|
||||
|
@ -112,118 +218,67 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
convenience; other instances may also be created.
|
||||
*/
|
||||
{
|
||||
BOOL added_locale, added_lang;
|
||||
id lang;
|
||||
NSArray *uL;
|
||||
NSEnumerator *enumerator;
|
||||
|
||||
if (setSharedDefaults)
|
||||
return sharedDefaults;
|
||||
setSharedDefaults = YES;
|
||||
// Create new sharedDefaults (NOTE: Not added to the autorelease pool!)
|
||||
sharedDefaults = [[self alloc] init];
|
||||
if (sharedDefaults == nil)
|
||||
{
|
||||
NSLog(@"WARNING - unable to create shared user defaults!\n");
|
||||
return nil;
|
||||
}
|
||||
|
||||
[sharedDefaults __createStandardSearchList];
|
||||
|
||||
if (sharedDefaults)
|
||||
/* Set up language constants */
|
||||
added_locale = NO;
|
||||
added_lang = NO;
|
||||
uL = [[self class] userLanguages];
|
||||
enumerator = [uL objectEnumerator];
|
||||
while ((lang = [enumerator nextObject]))
|
||||
{
|
||||
NSUserDefaults *defs;
|
||||
NSDictionary *registrationDefaults;
|
||||
NSArray *ampm;
|
||||
NSArray *long_day;
|
||||
NSArray *long_month;
|
||||
NSArray *short_day;
|
||||
NSArray *short_month;
|
||||
NSArray *earlyt;
|
||||
NSArray *latert;
|
||||
NSArray *hour_names;
|
||||
NSArray *ymw_names;
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
ampm = [NSArray arrayWithObjects: @"AM", @"PM", nil];
|
||||
short_month = [NSArray arrayWithObjects:
|
||||
@"Jan",
|
||||
@"Feb",
|
||||
@"Mar",
|
||||
@"Apr",
|
||||
@"May",
|
||||
@"Jun",
|
||||
@"Jul",
|
||||
@"Aug",
|
||||
@"Sep",
|
||||
@"Oct",
|
||||
@"Nov",
|
||||
@"Dec",
|
||||
nil];
|
||||
long_month = [NSArray arrayWithObjects:
|
||||
@"January",
|
||||
@"February",
|
||||
@"March",
|
||||
@"April",
|
||||
@"May",
|
||||
@"June",
|
||||
@"July",
|
||||
@"August",
|
||||
@"September",
|
||||
@"October",
|
||||
@"November",
|
||||
@"December",
|
||||
nil];
|
||||
short_day = [NSArray arrayWithObjects:
|
||||
@"Sun",
|
||||
@"Mon",
|
||||
@"Tue",
|
||||
@"Wed",
|
||||
@"Thu",
|
||||
@"Fri",
|
||||
@"Sat",
|
||||
nil];
|
||||
long_day = [NSArray arrayWithObjects:
|
||||
@"Sunday",
|
||||
@"Monday",
|
||||
@"Tuesday",
|
||||
@"Wednesday",
|
||||
@"Thursday",
|
||||
@"Friday",
|
||||
@"Saturday",
|
||||
nil];
|
||||
earlyt = [NSArray arrayWithObjects:
|
||||
@"prior",
|
||||
@"last",
|
||||
@"past",
|
||||
@"ago",
|
||||
nil];
|
||||
latert = [NSArray arrayWithObjects:
|
||||
@"next",
|
||||
nil];
|
||||
ymw_names = [NSArray arrayWithObjects:
|
||||
@"year",
|
||||
@"month",
|
||||
@"week",
|
||||
nil];
|
||||
hour_names = [NSArray arrayWithObjects:
|
||||
[NSArray arrayWithObjects: @"0", @"midnight", nil],
|
||||
[NSArray arrayWithObjects: @"12", @"noon", @"lunch", nil],
|
||||
[NSArray arrayWithObjects: @"10", @"morning", nil],
|
||||
[NSArray arrayWithObjects: @"14", @"afternoon", nil],
|
||||
[NSArray arrayWithObjects: @"19", @"dinner", nil],
|
||||
nil];
|
||||
registrationDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
ampm, NSAMPMDesignation,
|
||||
long_month, NSMonthNameArray,
|
||||
long_day, NSWeekDayNameArray,
|
||||
short_month, NSShortMonthNameArray,
|
||||
short_day, NSShortWeekDayNameArray,
|
||||
@"DMYH", NSDateTimeOrdering,
|
||||
@"tomorrow", NSNextDayDesignations,
|
||||
@"nextday", NSNextNextDayDesignations,
|
||||
@"yesterday", NSPriorDayDesignations,
|
||||
@"today", NSThisDayDesignations,
|
||||
earlyt, NSEarlierTimeDesignations,
|
||||
latert, NSLaterTimeDesignations,
|
||||
hour_names, NSHourNameDesignations,
|
||||
ymw_names, NSYearMonthWeekDesignations,
|
||||
nil];
|
||||
[sharedDefaults registerDefaults: registrationDefaults];
|
||||
NSString *path;
|
||||
NSDictionary *dict;
|
||||
path = [NSBundle pathForGNUstepResource: lang
|
||||
ofType: nil
|
||||
inDirectory: @"Resources/Languages"];
|
||||
dict = nil;
|
||||
if (path)
|
||||
dict = [NSDictionary dictionaryWithContentsOfFile: path];
|
||||
if (dict)
|
||||
{
|
||||
[sharedDefaults setVolatileDomain: dict forName: lang];
|
||||
added_lang = YES;
|
||||
}
|
||||
else if (added_locale == NO)
|
||||
{
|
||||
NSString *locale = GSSetLocale(nil);
|
||||
if (locale == nil)
|
||||
break;
|
||||
/* See if we can get the dictionary from i18n functions.
|
||||
Note that we get the dict from the current locale regardless
|
||||
of what 'lang' is, since it should match anyway. */
|
||||
/* Also, I don't think that the i18n routines can handle more than
|
||||
one locale, but tell me if I'm wrong... */
|
||||
if (GSLanguageFromLocale(locale))
|
||||
lang = GSLanguageFromLocale(locale);
|
||||
dict = GSDomainFromDefaultLocale();
|
||||
if (dict)
|
||||
[sharedDefaults setVolatileDomain: dict forName: lang];
|
||||
added_locale = YES;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (added_lang == NO)
|
||||
{
|
||||
NSLog(@"WARNING - unable to create shared user defaults!\n");
|
||||
/* Ack! We should never get here */
|
||||
NSLog(@"Improper installation: No language locale found");
|
||||
[sharedDefaults registerDefaults: [self _unlocalizedDefaults]];
|
||||
}
|
||||
return sharedDefaults;
|
||||
}
|
||||
|
@ -231,14 +286,33 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
|
||||
+ (NSArray*) userLanguages
|
||||
{
|
||||
NSMutableArray *uL = [NSMutableArray arrayWithCapacity: 5];
|
||||
NSArray *currLang = [[self standardUserDefaults]
|
||||
stringArrayForKey: @"Languages"];
|
||||
NSEnumerator *enumerator;
|
||||
id obj;
|
||||
|
||||
if (!currLang)
|
||||
{ // Try to build it from the env
|
||||
NSArray *currLang;
|
||||
NSString *locale;
|
||||
|
||||
if (userLanguages)
|
||||
return userLanguages;
|
||||
|
||||
userLanguages = RETAIN([NSMutableArray arrayWithCapacity: 5]);
|
||||
locale = GSSetLocale(@"");
|
||||
if (sharedDefaults == nil)
|
||||
{
|
||||
/* Create our own defaults to get "Languages" since sharedDefaults
|
||||
depends on us */
|
||||
NSUserDefaults *tempDefaults;
|
||||
tempDefaults = [[self alloc] init];
|
||||
if (tempDefaults)
|
||||
{
|
||||
[tempDefaults __createStandardSearchList];
|
||||
currLang = [tempDefaults stringArrayForKey: @"Languages"];
|
||||
RELEASE(tempDefaults);
|
||||
}
|
||||
}
|
||||
else
|
||||
currLang = [[self standardUserDefaults] stringArrayForKey: @"Languages"];
|
||||
if (currLang == nil && locale && GSLanguageFromLocale(locale))
|
||||
currLang = [NSArray arrayWithObject: GSLanguageFromLocale(locale)];
|
||||
if (currLang == nil)
|
||||
{
|
||||
const char *env_list;
|
||||
NSString *env;
|
||||
|
||||
|
@ -249,19 +323,17 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
currLang = RETAIN([env componentsSeparatedByString: @";"]);
|
||||
}
|
||||
}
|
||||
if (currLang)
|
||||
[uL addObjectsFromArray: currLang];
|
||||
|
||||
// Check if "English" is includet
|
||||
enumerator = [uL objectEnumerator];
|
||||
while ((obj = [enumerator nextObject]))
|
||||
{
|
||||
if ([obj isEqualToString: @"English"])
|
||||
return uL;
|
||||
}
|
||||
[uL addObject: @"English"];
|
||||
if (currLang)
|
||||
[userLanguages addObjectsFromArray: currLang];
|
||||
|
||||
/* Check if "English" is included. We do this to make sure all the
|
||||
required language constants are set somewhere if they aren't set
|
||||
in the default language */
|
||||
if ([userLanguages containsObject: @"English"] == NO)
|
||||
[userLanguages addObject: @"English"];
|
||||
|
||||
return uL;
|
||||
return userLanguages;
|
||||
}
|
||||
|
||||
+ (void) setUserLanguages: (NSArray*)languages
|
||||
|
@ -941,15 +1013,15 @@ static NSString *pathForUser(NSString *user)
|
|||
// 2. Application
|
||||
[_searchList addObject: processName];
|
||||
|
||||
// 3. User's preferred languages
|
||||
// 3. NSGlobalDomain
|
||||
[_searchList addObject: NSGlobalDomain];
|
||||
|
||||
// 4. User's preferred languages
|
||||
while ((object = [enumerator nextObject]))
|
||||
{
|
||||
[_searchList addObject: object];
|
||||
}
|
||||
|
||||
// 4. NSGlobalDomain
|
||||
[_searchList addObject: NSGlobalDomain];
|
||||
|
||||
// 5. NSRegistrationDomain
|
||||
[_searchList addObject: NSRegistrationDomain];
|
||||
|
||||
|
|
|
@ -248,6 +248,9 @@ NSString *NSLanguageName;
|
|||
|
||||
NSString *NSFormalName;
|
||||
|
||||
/* For GNUstep */
|
||||
NSString *NSLocale;
|
||||
|
||||
|
||||
/*
|
||||
* Keys for the NSDictionary returned by [NSConnection -statistics]
|
||||
|
@ -409,6 +412,8 @@ GSBuildStrings()
|
|||
= [[GSCString alloc] initWithCString: "NSLaterTimeDesignations"];
|
||||
NSLoadedClasses
|
||||
= [[GSCString alloc] initWithCString: "NSLoadedClasses"];
|
||||
NSLocale
|
||||
= [[GSCString alloc] initWithCString: "NSLocale"];
|
||||
*(NSString**)&NSMallocException
|
||||
= [[GSCString alloc] initWithCString: "NSMallocException"];
|
||||
NSMonthNameArray
|
||||
|
|
|
@ -12,6 +12,9 @@ int _MB_init_runtime()
|
|||
}
|
||||
#endif
|
||||
|
||||
#define DESCRIP(obj) [obj description]
|
||||
#define DESCRIP_FORMAT(obj) [obj descriptionWithCalendarFormat: nil]
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
@ -34,25 +37,25 @@ if ([(NSDate*) [NSCalendarDate date] compare:
|
|||
{
|
||||
// Create NSDate instances
|
||||
a = [NSDate date];
|
||||
printf("+[date] -- %s\n", [[a description] cString]);
|
||||
printf("+[date] -- %s\n", [DESCRIP(a) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceNow: 0];
|
||||
printf("+[dateWithTimeIntervalSinceNow: 0] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceNow: 600];
|
||||
printf("+[dateWithTimeIntervalSinceNow: 600] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSince1970: 0];
|
||||
printf("+[dateWithTimeIntervalSince1970: 0] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSince1970: -600];
|
||||
printf("+[dateWithTimeIntervalSince1970: -600] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceReferenceDate: 0];
|
||||
printf("+[dateWithTimeIntervalSinceReferenceDate: 0] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceReferenceDate: 300];
|
||||
printf("+[dateWithTimeIntervalSinceReferenceDate: 300] -- %s\n",
|
||||
[[b description] cString]);
|
||||
[DESCRIP(b) cString]);
|
||||
|
||||
// Comparisons
|
||||
|
||||
|
@ -68,19 +71,19 @@ if ([(NSDate*) [NSCalendarDate date] compare:
|
|||
|
||||
c = [a earlierDate: b];
|
||||
if (c == a)
|
||||
printf("%s is earlier than %s\n", [[a description] cString],
|
||||
[[b description] cString]);
|
||||
printf("%s is earlier than %s\n", [DESCRIP(a) cString],
|
||||
[DESCRIP(b) cString]);
|
||||
else
|
||||
printf("ERROR: %s is not earlier than %s\n", [[a description] cString],
|
||||
[[b description] cString]);
|
||||
printf("ERROR: %s is not earlier than %s\n", [DESCRIP(a) cString],
|
||||
[DESCRIP(b) cString]);
|
||||
|
||||
c = [a laterDate: b];
|
||||
if (c == b)
|
||||
printf("%s is later than %s\n", [[b description] cString],
|
||||
[[a description] cString]);
|
||||
printf("%s is later than %s\n", [DESCRIP(b) cString],
|
||||
[DESCRIP(a) cString]);
|
||||
else
|
||||
printf("ERROR: %s is not later than %s\n", [[b description] cString],
|
||||
[[a description] cString]);
|
||||
printf("ERROR: %s is not later than %s\n", [DESCRIP(b) cString],
|
||||
[DESCRIP(a) cString]);
|
||||
}
|
||||
|
||||
// NSCalendarDate tests
|
||||
|
@ -90,7 +93,7 @@ if ([(NSDate*) [NSCalendarDate date] compare:
|
|||
|
||||
// Create an NSCalendarDate with current date and time
|
||||
c = [NSCalendarDate calendarDate];
|
||||
printf("+[calendarDate] -- %s\n", [[c description] cString]);
|
||||
printf("+[calendarDate] -- %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("-[dayOfMonth] %d\n", [c dayOfMonth]);
|
||||
printf("-[dayOfWeek] %d\n", [c dayOfWeek]);
|
||||
printf("-[dayOfYear] %d\n", [c dayOfYear]);
|
||||
|
@ -111,7 +114,7 @@ if ([(NSDate*) [NSCalendarDate date] compare:
|
|||
|
||||
c = [NSCalendarDate dateWithString: @"1996-10-09 0:00:01"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("calendar date %s\n", [[c description] cString]);
|
||||
printf("calendar date %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("-[dayOfCommonEra] %d\n", [c dayOfCommonEra]);
|
||||
printf("-[dayOfMonth] %d\n", [c dayOfMonth]);
|
||||
printf("-[dayOfWeek] %d\n", [c dayOfWeek]);
|
||||
|
@ -149,63 +152,63 @@ if ([(NSDate*) [NSCalendarDate date] compare:
|
|||
printf("\nY2K checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"1999-12-31 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [[c description] cString]);
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("YYYY-MM-DD %d-%d-%d\n", [c yearOfCommonEra], [c monthOfYear], [c dayOfMonth]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [[c description] cString]);
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [[c description] cString]);
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [[c description] cString]);
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [[c description] cString]);
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\nY2K is a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2000-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [[c description] cString]);
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [[c description] cString]);
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [[c description] cString]);
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [[c description] cString]);
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [[c description] cString]);
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:5 minute:0 second:0];
|
||||
printf("Add five hours - %s\n", [[c description] cString]);
|
||||
printf("Add five hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:1 month:0 day:0 hour:0 minute:0 second:0];
|
||||
printf("Add one year - %s\n", [[c description] cString]);
|
||||
printf("Add one year - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:-1 hour:0 minute:0 second:0];
|
||||
printf("Subtract one day - %s\n", [[c description] cString]);
|
||||
printf("Subtract one day - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:1 month:0 day:1 hour:0 minute:0 second:0];
|
||||
printf("Add a year and a day - %s\n", [[c description] cString]);
|
||||
printf("Add a year and a day - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\n2004 is a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2004-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [[c description] cString]);
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [[c description] cString]);
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [[c description] cString]);
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [[c description] cString]);
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [[c description] cString]);
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\n2100 is NOT a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2100-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [[c description] cString]);
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [[c description] cString]);
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [[c description] cString]);
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [[c description] cString]);
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [[c description] cString]);
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
|
|
@ -43,6 +43,8 @@ TOOL_NAME = gdnc gsdoc defaults plmerge \
|
|||
plparse sfparse pldes plser
|
||||
CTOOL_NAME = gdomap
|
||||
|
||||
TEST_TOOL_NAME = locale_alias
|
||||
|
||||
# The source files to be compiled
|
||||
gdomap_C_FILES = gdomap.c
|
||||
gdnc_OBJC_FILES = gdnc.m
|
||||
|
@ -57,6 +59,8 @@ plmerge_OBJC_FILES = plmerge.m
|
|||
plparse_OBJC_FILES = plparse.m
|
||||
sfparse_OBJC_FILES = sfparse.m
|
||||
|
||||
locale_alias_OBJC_FILES = locale_alias.m
|
||||
|
||||
SOURCES = gdomap.c gdnc.m defaults.m dread.m dremove.m dwrite.m
|
||||
|
||||
HEADERS = gdomap.h gdnc.h
|
||||
|
@ -70,6 +74,7 @@ include Makefile.preamble
|
|||
|
||||
include $(GNUSTEP_MAKEFILES)/ctool.make
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
include $(GNUSTEP_MAKEFILES)/test-tool.make
|
||||
|
||||
include Makefile.postamble
|
||||
|
||||
|
|
121
Tools/locale_alias.m
Normal file
121
Tools/locale_alias.m
Normal file
|
@ -0,0 +1,121 @@
|
|||
/* locale_alias - Test program to create a file of locale to language name
|
||||
aliases
|
||||
|
||||
Written: Adam Fedor <fedor@gnu.org>
|
||||
Date: Oct 2000
|
||||
|
||||
AFAIK: This only works on machines that support setlocale.
|
||||
The files created may require hand editing.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <base/GSLocale.h>
|
||||
|
||||
#define MAXSTRING 100
|
||||
|
||||
static int debug=1;
|
||||
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
int
|
||||
loc_read_file(const char *dir, const char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
char name[1000], *s;
|
||||
char buf[1000];
|
||||
char locale[MAXSTRING], language[MAXSTRING], country[MAXSTRING];
|
||||
|
||||
if (strcmp(file, "POSIX") == 0)
|
||||
return 0;
|
||||
|
||||
sprintf(name, "%s/%s", dir, file);
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
|
||||
language[0] = '\0';
|
||||
country[0] = '\0';
|
||||
while (1)
|
||||
{
|
||||
fgets(buf, MAXSTRING, fp);
|
||||
if (strstr(buf, "anguage") != NULL)
|
||||
{
|
||||
sscanf(&buf[2], "%s", language);
|
||||
}
|
||||
if ((s = strstr(buf, "ocale for")) != NULL)
|
||||
{
|
||||
strcpy(country, s+10);
|
||||
s = strchr(country, '\n');
|
||||
if (s)
|
||||
*s = '\0';
|
||||
}
|
||||
if (strlen(language) > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
strcpy(locale, file);
|
||||
if (strlen(country) > 0 && strcmp(country, language) != 0)
|
||||
{
|
||||
strcat(country, language);
|
||||
[dict setObject: [NSString stringWithCString: country]
|
||||
forKey: [NSString stringWithCString: locale]];
|
||||
}
|
||||
locale[2] = '\0';
|
||||
[dict setObject: [NSString stringWithCString: language]
|
||||
forKey: [NSString stringWithCString: locale]];
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Go through all the files in the directory */
|
||||
int
|
||||
loc_get_files(const char *dir)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
|
||||
dirp = opendir(dir);
|
||||
while ((dp = readdir(dirp)) != NULL)
|
||||
{
|
||||
if (isalpha((dp->d_name)[0]))
|
||||
{
|
||||
if (debug)
|
||||
printf(" checking %s ...\n", dp->d_name);
|
||||
loc_read_file(dir, dp->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
NSString *lang;
|
||||
char *l;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
|
||||
l = setlocale(LC_ALL, "");
|
||||
printf("Locale is %s\n", l);
|
||||
|
||||
/* Create Locale.aliases */
|
||||
dict = [NSMutableDictionary dictionary];
|
||||
loc_get_files("/usr/share/i18n/locales");
|
||||
[dict writeToFile: @"Locale.aliases" atomically: NO];
|
||||
|
||||
/* Write out a skeleton file from the current locale */
|
||||
dict = GSDomainFromDefaultLocale();
|
||||
lang = GSLanguageFromLocale(GSSetLocale(NULL));
|
||||
if (lang == nil)
|
||||
lang = @"Locale";
|
||||
if (dict)
|
||||
[dict writeToFile: lang atomically: NO];
|
||||
|
||||
DESTROY(pool);
|
||||
return 0;
|
||||
}
|
2
configure
vendored
2
configure
vendored
|
@ -2791,7 +2791,7 @@ else
|
|||
fi
|
||||
done
|
||||
|
||||
for ac_hdr in sys/mount.h sys/types.h windows.h
|
||||
for ac_hdr in sys/mount.h sys/types.h windows.h locale.h
|
||||
do
|
||||
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
|
||||
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
|
||||
|
|
|
@ -540,7 +540,7 @@ AC_CHECK_HEADERS(values.h)
|
|||
# Header files and functions for files and filesystems
|
||||
#--------------------------------------------------------------------
|
||||
AC_CHECK_HEADERS(sys/stat.h sys/vfs.h sys/statfs.h sys/statvfs.h pwd.h grp.h)
|
||||
AC_CHECK_HEADERS(sys/mount.h sys/types.h windows.h)
|
||||
AC_CHECK_HEADERS(sys/mount.h sys/types.h windows.h locale.h)
|
||||
saved_LIBS="$LIBS"
|
||||
LIBS="$LIBS -lm"
|
||||
AC_CHECK_FUNCS(statvfs symlink readlink geteuid rint)
|
||||
|
|
Loading…
Reference in a new issue