New: first work on localization

This commit is contained in:
Alexandre Wilhelm committed 2015-04-17 17:16:11 -07:00
1 parent c13f1991c9
commit c171a37f24
6 files changed
+262 -8

No files matched your search

+1
View File
@@ -32,6 +32,7 @@
@import "_CPCibObjectData.j"
@import "_CPCibProxyObject.j"
@import "_CPCibWindowTemplate.j"
@import "_CPLocalizableString.j"
CPCibOwner = @"CPCibOwner";
CPCibTopLevelObjects = @"CPCibTopLevelObjects";
+66
View File
@@ -0,0 +1,66 @@
/*
* _CPLocalizableString.j
* AppKit
*
* Created by Alexandre Wilhelm.
* Copyright 2008, 280 North, Inc.
*
* 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/CPString.j>
@implementation _CPLocalizableString : CPString
{
CPString _dev @accessors(property=dev);
CPString _key @accessors(property=key);
}
- (id)init
{
if (self = [super init])
{
}
return self;
}
@end
var CPLocalizableStringDev = @"CPLocalizableStringDev",
CPLocalizableStringKey = @"CPLocalizableStringKey";
@implementation _CPLocalizableString (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
[self init];
_dev = [aCoder decodeObjectForKey:CPLocalizableStringDev];
_key = [aCoder decodeObjectForKey:CPLocalizableStringKey];
//TODO: here we should not return self but the string from CPLocalizedStringFromTable
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:_dev forKey:CPLocalizableStringDev];
[aCoder encodeObject:_key forKey:CPLocalizableStringKey];
}
@end
+54
View File
@@ -212,4 +212,58 @@ var CPBundlesForURLStrings = { };
return [super description] + "(" + [self bundlePath] + ")";
}
#pragma mark -
#pragma mark Localization
+ (CPArray)preferredLocalizationsFromArray:(CPArray)localizationsArray
{
return CFBundleCopyPreferredLocalizationsFromArray(localizationsArray);
}
+ (CPArray)preferredLocalizationsFromArray:(CPArray)localizationsArray forPreferences:(CPArray)preferencesArray
{
return CFBundleCopyLocalizationsForPreferences(localizationsArray, preferencesArray);
}
- (CPArray)preferredLocalizations
{
}
- (CPString)developmentLocalization
{
return [self objectForInfoDictionaryKey:@"CFBundleDevelopmentRegion"];
}
- (CPArray)localizations
{
return CFBundleCopyBundleLocalizations(_bundle);
}
- (CPDictionary)localizedInfoDictionary
{
}
- (CPString)localizedStringForKey:(CPString)aKey value:(CPString)aValue table:(CPString)aTable
{
return CFBundleCopyLocalizedString(_bundle, aKey, aValue, aTable);
}
@end
function CPLocalizedString(key, comment)
{
return CFCopyLocalizedString(key, comment);
}
function CPLocalizedStringFromTable(key, table, comment)
{
return CFCopyLocalizedStringFromTableInBundle(key, table, comment);
}
function CFCopyLocalizedStringFromTableInBundle(key, table, bundle, comment)
{
return CFCopyLocalizedStringFromTableInBundle(key, table, bundle._bundle, comment);
}
+81 -8
View File
@@ -20,18 +20,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
var CFBundleUnloaded = 0,
CFBundleLoading = 1 << 0,
CFBundleLoadingInfoPlist = 1 << 1,
CFBundleLoadingExecutable = 1 << 2,
CFBundleLoadingSpritedImages = 1 << 3,
CFBundleLoaded = 1 << 4;
var CFBundleUnloaded = 0,
CFBundleLoading = 1 << 0,
CFBundleLoadingInfoPlist = 1 << 1,
CFBundleLoadingExecutable = 1 << 2,
CFBundleLoadingSpritedImages = 1 << 3,
CFBundleLoadingLocalizableStrings = 1 << 4,
CFBundleLoaded = 1 << 5;
var CFBundlesForURLStrings = { },
CFBundlesForClasses = { },
CFBundlesWithIdentifiers = { },
CFCacheBuster = new Date().getTime(),
CFTotalBytesLoaded = 0,
CFCacheBuster = new Date().getTime(),
CFTotalBytesLoaded = 0,
CPApplicationSizeInBytes = 0;
GLOBAL(CFBundle) = function(/*CFURL|String*/ aURL)
@@ -58,6 +59,8 @@ GLOBAL(CFBundle) = function(/*CFURL|String*/ aURL)
this._infoDictionary = new CFDictionary();
this._eventDispatcher = new EventDispatcher(this);
this._localizableStrings = [];
}
DISPLAY_NAME(CFBundle);
@@ -354,6 +357,7 @@ function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute)
loadExecutableForBundle(aBundle, success, failure, progress);
loadSpritedImagesForBundle(aBundle, success, failure, progress);
loadLocalizableStringsForBundle(aBundle, success, failure, progress);
if (aBundle._loadStatus === CFBundleLoading)
return success();
@@ -490,6 +494,14 @@ function loadSpritedImagesForBundle(/*Bundle*/ aBundle, success, failure, progre
}, failure, progress);
}
function loadLocalizableStringsForBundle(/*Bundle*/, aBundle, success, failure, progress)
{
aBundle._loadStatus |= CFBundleLoadingLocalizableStrings;
//TODO: Here we need to load the .xstrings
aBundle._loadStatus &= ~CFBundleLoadingLocalizableStrings;
}
var CFBundleSpriteSupportListeners = [],
CFBundleSupportedSpriteType = -1,
CFBundleNoSpriteType = 0,
@@ -738,3 +750,64 @@ CFBundle.prototype.pathForResource = function(aResource)
{
return this.resourceURL(aResource).absoluteString();
};
function CFBundleCopyLocalizedString(/*Bundle*/ bundle, key, value, tableName)
{
return CFCopyLocalizedStringWithDefaultValue(key, tableName, bundle, value, null);
}
function CFBundleCopyLocalizationsForPreferences(locArray, prefArray)
{
}
function CFBundleCopyPreferredLocalizationsFromArray(locArray)
{
}
function CFBundleCopyLocalizationsForURL(url)
{
}
function CFBundleCopyBundleLocalizations(/*Bundle*/ aBundle)
{
}
function CFCopyLocalizedString(key, comment)
{
return CFCopyLocalizedStringFromTable(key, "Localizable", comment);
}
function CFCopyLocalizedStringFromTable(key, tableName, comment)
{
return CFCopyLocalizedStringFromTableInBundle(key, tableName, CFBundleGetMainBundle(), comment);
}
function CFCopyLocalizedStringFromTableInBundle(key, tableName, bundle, comment)
{
return CFCopyLocalizedStringWithDefaultValue(key, tableName, bundle, null, comment);
}
function CFCopyLocalizedStringWithDefaultValue(key, tableName, bundle, value, comment)
{
var string;
if (!tableName)
tableName = "Localizable";
var localizableString = bundle._localizableStrings[tableName];
//TODO : What about the comment and context ?
string = localizableString[key];
return string || value;
}
function CFBundleGetMainBundle()
{
return CFBundle.mainBundle();
}
+1
View File
@@ -46,6 +46,7 @@
@import "NSImageView.j"
@import "NSLayoutConstraint.j"
@import "NSLevelIndicator.j"
@import "NSLocalizableString.j"
@import "NSMatrix.j"
@import "NSMenu.j"
@import "NSMenuItem.j"
+59
View File
@@ -0,0 +1,59 @@
/*
* NSLocalizableString.j
* AppKit
*
* Created by Alexandre Wilhelm.
* Copyright 2008, 280 North, Inc.
*
* 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 <AppKit/_CPLocalizableString.j>
@implementation _CPLocalizableString (CPCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
self = [self init];
if (self)
{
_dev = [aCoder decodeObjectForKey:@"NSDev"];
_key = [aCoder decodeObjectForKey:@"NSKey"];
}
return self;
}
@end
@implementation NSLocalizableString : _CPLocalizableString
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [_CPLocalizableString class];
}
@end