Created
December 23, 2008 01:08
-
-
Save nickjs/39212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* CPLocale.j | |
* Foundation | |
* | |
* Created by Nicholas Small. | |
* Copyright 2008, Nicholas Small | |
* | |
* This library is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU Lesser General Public | |
* License as published by the Free Software Foundation; either | |
* version 2.1 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 | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this library; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
@import <Foundation/CPObject.j> | |
@import <Foundation/CPArray.j> | |
@import <Foundation/CPDictionary.j> | |
@import <AppKit/CPCookie.j> | |
var localeCookie = [[CPCookie alloc] initWithName:@"CPLocaleCookie"], | |
_sharedSystemLocale = nil, | |
_sharedCurrentLocale = nil, | |
_availableLocales = nil; | |
objj_import(@"Data/"+[CPLocale currentLocale]+".strings", YES, function(){}); | |
@implementation CPLocale : CPObject | |
{ | |
CPDictionary _locale; | |
} | |
+ (id)systemLocale | |
{ | |
if(_sharedSystemLocale == nil) | |
_sharedSystemLocale = [[CPLocale alloc] initWithLocaleIdentifier:[self _systemLocale]]; | |
return _sharedSystemLocale; | |
} | |
+ (id)_systemLocale | |
{ | |
//FIXME, use CPCompatibility? | |
if(navigator) | |
{ | |
if(navigator.language) | |
{ | |
return navigator.language; | |
} | |
else if(navigator.browserLanguage) | |
{ | |
return navigator.browserLanguage; | |
} | |
else if(navigator.systemLanguage) | |
{ | |
return navigator.systemLanguage; | |
} | |
else if(navigator.userLanguage) | |
{ | |
return navigator.userLanguage; | |
} | |
} | |
} | |
+ (id)currentLocale | |
{ | |
if(_sharedCurrentLocale == nil) | |
{ | |
var localeIdentifier; | |
if(localeCookie && [localeCookie value]) | |
localeIdentifier = [localeCookie value]; | |
else | |
localeIdentifier = [self systemLocale]; | |
} | |
} | |
+ (CPArray)availableLocaleIdentifiers | |
{ | |
return _availableLocales; | |
} | |
+ (void)setAvailableLocaleIdentifiers:(CPArray)array | |
{ | |
_availableLocales = array; | |
} | |
+ (CPString)canonicalLocaleIdentifierFromString:(CPString)string | |
{ | |
} | |
+ (CPDictionary)componentsFromLocaleIdentifier:(CPString)identifier | |
{ | |
} | |
+ (CPString)localeIdentifierFromComponents:(CPDictionary)components | |
{ | |
} | |
+ (CPArray)ISOCountryCodes | |
{ | |
} | |
+ (CPArray)ISOLanguageCodes | |
{ | |
} | |
+ (CPArray)ISOCurrencyCodes | |
{ | |
} | |
+ (CPArray)commonISOCurrencyCodes | |
{ | |
} | |
+ (CPArray)preferredLanguages | |
{ | |
} | |
- (id)initWithLocaleIdentifier:(CPString)identifier | |
{ | |
} | |
- (CPString)localeIdentifier | |
{ | |
} | |
- (id)objectForKey:(CPString)key | |
{ | |
} | |
- (CPString)displayNameForKey:(CPString)key value:(id)value | |
{ | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment