0
我找到了this plugin並試圖讓它在PhoneGap 2.1上工作。我更新如下。 我把插件引用Cordova.plist並創建可本地化的字符串。Phonegap 2.1 iOS本地化
因爲這NSLog(jsString);
代碼的打印正確的本地化字符串到控制檯
[6766:c07] <null>("Hello");
但我不能讓它在JS文件的工作。它不會給出任何錯誤,但也不起作用。即使我刪除result
,警報框也不會彈出。
app.Localizer.get('HelloKey',
function(result) {
alert("We got a setting: " + result);
});
我的修改:
localizable.js
**************
function localizable() {
}
localizable.prototype.get = function(name, success)
{
Cordova.exec("localizable.get", name, success);
};
Cordova.addConstructor(function()
{
if(!window.plugins)
{
window.plugins = {};
}
window.plugins.localizable = new localizable();
});
-
localizable.h
*************
#import <Cordova/CDVPlugin.h>
#import <Foundation/Foundation.h>
@interface localizable : CDVPlugin {}
- (void) get:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
-
localizable.m
*************
#import "localizable.h"
@implementation localizable
- (void)get:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSUInteger argc = [arguments count];
NSString* jsString;
if(argc == 2)
{
NSString *key = [arguments objectAtIndex:0];
NSString *successCallback = [arguments objectAtIndex:1];
NSString *returnVar = NSLocalizedString(key, nil);
jsString = [NSString stringWithFormat:@"%@(\"%@\");",successCallback,returnVar];
NSLog(jsString);
[self writeJavascript:jsString]; //Write back to JS
}
}
@end