mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-03 10:00:51 +00:00
Updated localisation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4115 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b45195874d
commit
e846ffba24
1 changed files with 59 additions and 24 deletions
|
@ -470,6 +470,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
||||||
NSMapRemove(_bundles, _path);
|
NSMapRemove(_bundles, _path);
|
||||||
[_bundleClasses release];
|
[_bundleClasses release];
|
||||||
[_infoDict release];
|
[_infoDict release];
|
||||||
|
[_localizations release];
|
||||||
[_path release];
|
[_path release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -724,7 +725,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) pathsForResourcesOfType: (NSString *)extension
|
- (NSArray *) pathsForResourcesOfType: (NSString *)extension
|
||||||
inDirectory: (NSString *)bundlePath
|
inDirectory: (NSString *)bundlePath
|
||||||
{
|
{
|
||||||
NSString *path;
|
NSString *path;
|
||||||
NSArray* paths;
|
NSArray* paths;
|
||||||
|
@ -766,42 +767,76 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) localizedStringForKey: (NSString *)key
|
- (NSString *) localizedStringForKey: (NSString *)key
|
||||||
value: (NSString *)value
|
value: (NSString *)value
|
||||||
table: (NSString *)tableName
|
table: (NSString *)tableName
|
||||||
{
|
{
|
||||||
NSString* new_string;
|
NSDictionary *table;
|
||||||
|
NSString *newString;
|
||||||
|
|
||||||
if (!tableName)
|
if (tableName == nil || [tableName isEqualToString: @""] == YES)
|
||||||
tableName = [self pathForResource: @"Localizable" ofType: @"strings"];
|
|
||||||
if (!tableName)
|
|
||||||
{
|
{
|
||||||
NSArray* resources = [self pathsForResourcesOfType: @"strings"
|
tableName = @"Localizable";
|
||||||
inDirectory: nil];
|
}
|
||||||
if (resources && [resources count])
|
else if ([@"strings" isEqual: [tableName pathExtension]] == YES)
|
||||||
tableName = [resources objectAtIndex: 0];
|
{
|
||||||
|
tableName = [tableName stringByDeletingPathExtension];
|
||||||
}
|
}
|
||||||
|
|
||||||
new_string = value;
|
if (_localizations == nil)
|
||||||
if (tableName)
|
_localizations = [[NSMutableDictionary alloc] initWithCapacity: 1];
|
||||||
|
|
||||||
|
table = [_localizations objectForKey: tableName];
|
||||||
|
if (table == nil)
|
||||||
{
|
{
|
||||||
NSDictionary* dict;
|
NSString *tablePath;
|
||||||
dict = [[[NSDictionary alloc] initWithContentsOfFile: tableName]
|
|
||||||
autorelease];
|
tablePath = [self pathForResource: tableName ofType: @"strings"];
|
||||||
new_string = [dict objectForKey: key];
|
if (tablePath)
|
||||||
if (!new_string)
|
{
|
||||||
new_string = value;
|
NSString *tableContent;
|
||||||
|
|
||||||
|
tableContent = [NSString stringWithContentsOfFile: tablePath];
|
||||||
|
NS_DURING
|
||||||
|
{
|
||||||
|
table = [tableContent propertyListFromStringsFileFormat];
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
NSLog(@"Failed to parse strings file %@ - %@",
|
||||||
|
tablePath, localException);
|
||||||
|
table = nil;
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
|
}
|
||||||
|
else
|
||||||
|
NSLog(@"Failed to locate strings file %@", tablePath);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we couldn't find, or couldn't parse the strings table,
|
||||||
|
* we create an empty dictionary to avoid attempting to read it again..
|
||||||
|
*/
|
||||||
|
if (table == nil)
|
||||||
|
table = [NSDictionary dictionary];
|
||||||
|
[_localizations setObject: table forKey: tableName];
|
||||||
}
|
}
|
||||||
if (!new_string || [new_string length] == 0)
|
|
||||||
|
if (key == nil || (newString = [table objectForKey: key]) == nil)
|
||||||
{
|
{
|
||||||
NSString* show = [[NSUserDefaults standardUserDefaults]
|
NSString *show = [[NSUserDefaults standardUserDefaults]
|
||||||
objectForKey: NSShowNonLocalizedStrings];
|
objectForKey: NSShowNonLocalizedStrings];
|
||||||
if (!show || [show isEqual: @"YES"])
|
if (!show || [show isEqual: @"YES"])
|
||||||
new_string = [key uppercaseString];
|
newString = [key uppercaseString];
|
||||||
else
|
else
|
||||||
new_string = key;
|
{
|
||||||
|
newString = value;
|
||||||
|
if (newString == nil || [newString isEqualToString: @""] == YES)
|
||||||
|
newString = key;
|
||||||
|
}
|
||||||
|
if (newString == nil)
|
||||||
|
newString = @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_string;
|
return newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) stripAfterLoading: (BOOL)flag
|
+ (void) stripAfterLoading: (BOOL)flag
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue