In my company, I need to localize our jni-library. Our main application is written in Java and over JNI we are working with CEF3
(I know, there is a JCEF, but I need to resolve problem with CEF3)
The jnilib handles main menu like in this picture
I need to localize this menu, english and german.
What I did:
But every time I only get the key as value. If I print out BundlePath I get following path: (jdk home dir)
*/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin*
If I copy en.lproj and de.lproj to the bin dir (for test purposes), the localization is still not used.
I don't know what to do :/
I am working on MacOsX 10.10.3 with Xcode 6.3
Edit: Code snipped, that doesn't work, too.
NSString *path = @"pathtobundle/JNILIB.bundle";
bundle = [[NSBundle bundleWithPath:path] retain];
NSString *tmp = NSLocalizedStringFromTableInBundle(key, nil, bundle, nil);
jnilib.bundle structure:
/JNILIB.bundle
/en.lproj
/Localized.strings
/de.lproj
/Localized.strings
I was able to find a solution.
Here the link which helped me a lot: static library and internationalization
Here my code:
NSString *MyLocalizedString(NSString* key, NSString* comment)
{
static NSBundle* bundle = nil;
if (!bundle) {
NSString *path_tmp = @"pathToBundle/JNILIB.bundle";
NSBundle *libraryBundle = [NSBundle bundleWithPath:path_tmp];
NSString *langID = [[NSLocale preferredLanguages] objectAtIndex:0];
NSLog(@"preferredLanguage: %@", langID);
NSString *path = [libraryBundle pathForResource:langID ofType:@"lproj"];
NSLog(@"libraryBundle : %@", path);
bundle = [[NSBundle bundleWithPath:path] retain];
}
return [bundle localizedStringForKey:key value:@"Can't be found!" table:@"Localized"];
}
Bundle structure:
foo.bundle/
Contents/
Resources/
en.lproj/
Localized.strings
de.lproj/
Localized.strings