Created
March 13, 2017 09:09
-
-
Save Darkyenus/5df878ac3d6cc74655f942479a416088 to your computer and use it in GitHub Desktop.
String Localization Workaround in MOE
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
import apple.NSObject; | |
import org.moe.natj.general.NatJ; | |
import org.moe.natj.general.Pointer; | |
import org.moe.natj.general.ann.Runtime; | |
import org.moe.natj.objc.ObjCRuntime; | |
import org.moe.natj.objc.ann.ObjCClassBinding; | |
import org.moe.natj.objc.ann.ObjCClassName; | |
import org.moe.natj.objc.ann.Selector; | |
@Runtime(ObjCRuntime.class) | |
@ObjCClassName("LocalizationUtil") | |
@ObjCClassBinding | |
public class LocalizationUtil extends NSObject { | |
static { | |
NatJ.register(); | |
} | |
@Selector("alloc") | |
public static native LocalizationUtil alloc(); | |
// Initializes an object with the default | |
@Selector("init") | |
public native LocalizationUtil init(); | |
protected LocalizationUtil(Pointer peer) { | |
super(peer); | |
} | |
@Selector("localize:") | |
public static native String localize(String key); | |
@Selector("localize1:with:") | |
public static native String localize1(String key, int param); | |
} |
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
// | |
// LocalizationUtil.m | |
// | |
// Created by Jan Polák on 13/03/17. | |
// Public domain. | |
// | |
#import <Foundation/Foundation.h> | |
@class LocalizationUtil; | |
@interface LocalizationUtil : NSObject | |
+ (NSString *) localize:(NSString *) key; | |
+ (NSString *) localize1:(NSString *) key with:(int) param; | |
@end | |
@implementation LocalizationUtil | |
+ (NSString *) localize:(NSString *) key { | |
return NSLocalizedString(key, nil); | |
} | |
+ (NSString *) localize1:(NSString *) key with:(int) param { | |
return [NSString localizedStringWithFormat:NSLocalizedString(key, nil), param]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do not forget to add the
LocalizationUtil.m
to the Xcode project!