Implement iOS localization code
MODIFY
plugin.xml
plugin.xml
This plugin allows your application to use the native Google Maps views instead of the Google Maps JavaScript API v3.
The native map view is faster, use less network usage, display 3D views, and even work on offline network.
</description>
- <repo>https://github.com/mapsplugin/cordova-plugin-googlemaps</repo>
+ <repo>https://github.com/mapsplugin/cordova-plugin-googlemaps.git</repo>
<issue>https://github.com/mapsplugin/cordova-plugin-googlemaps/issues</issue>
<author>Masashi Katsumata</author>
@@ -242,14 +242,15 @@ The native map view is faster, use less network usage, display 3D views, and eve
<preference name="ANDROID_SUPPORT_V4_VERSION" default="24.1.0" />
<framework src="com.android.support:support-core-utils:$ANDROID_SUPPORT_V4_VERSION" />
+
+ <resource-file src="src/android/res/values/pgm_strings.xml" target="res/values/pgm_strings.xml" />
+ <resource-file src="src/android/res/values-ja/pgm_strings.xml" target="res/values-ja/pgm_strings.xml" />
</platform>
<!-- ios -->
<platform name="ios">
<preference name="API_KEY_FOR_IOS" />
- <preference name="LOCATION_WHEN_IN_USE_DESCRIPTION" default="Show your location on the map"/>
- <preference name="LOCATION_ALWAYS_USAGE_DESCRIPTION" default="Trace your location on the map" />
<js-module name="CordovaGoogleMaps" src="www/googlemaps-cdv-plugin.js">
<clobbers target="plugin.google.maps" />
@@ -355,16 +356,21 @@ The native map view is faster, use less network usage, display 3D views, and eve
<header-file src="src/ios/GoogleMaps/UIImageCache.h" />
<source-file src="src/ios/GoogleMaps/UIImageCache.m" />
- <config-file target="*-Info.plist" parent="Google Maps API Key">
- <string>$API_KEY_FOR_IOS</string>
+ <config-file target="*-Info.plist" parent="CFBundleDevelopmentRegion">
+ <array>
+ <string>Japanese</string>
+ </array>
</config-file>
-
- <config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
- <string>$LOCATION_WHEN_IN_USE_DESCRIPTION</string>
+ <config-file target="*-Info.plist" parent="CFBundleLocalizations">
+ <array>
+ <string>ja</string>
+ </array>
</config-file>
+ <resource-file src="src/ios/strings/Base.lproj/pgm_Localizable.strings" target="Base.lproj/pgm_Localizable.strings" />
+ <resource-file src="src/ios/strings/ja.lproj/pgm_Localizable.strings" target="ja.lproj/pgm_Localizable.strings" />
- <config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
- <string>$LOCATION_ALWAYS_USAGE_DESCRIPTION</string>
+ <config-file target="*-Info.plist" parent="Google Maps API Key">
+ <string>$API_KEY_FOR_IOS</string>
</config-file>
<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">

ADD
src/android/res/values/pgm_strings.xml
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="welcome_message">Hello, welcome</string>
+</resources>

MODIFY
src/ios/GoogleMaps/CordovaGoogleMaps.m
src/ios/GoogleMaps/CordovaGoogleMaps.m
- (void)pluginInitialize
{
+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
self.webView.backgroundColor = [UIColor clearColor];
self.webView.opaque = NO;
//-------------------------------
NSString *APIKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Google Maps API Key"];
if (APIKey == nil) {
- NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
- NSString *bundleName = [NSString stringWithFormat:@"%@", [info objectForKey:@"CFBundleDisplayName"]];
- NSString *message = [NSString stringWithFormat:@"Please replace 'API_KEY_FOR_IOS' in the platforms/ios/%@/%@-Info.plist with your API Key!", bundleName, bundleName];
+ NSString *errorTitle = PGM_LOCALIZATION(@"APIKEY_IS_UNDEFINED_TITLE", nil);
+ NSString *errorMsg = PGM_LOCALIZATION(@"APIKEY_IS_UNDEFINED_MESSAGE", nil);
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"API key is not setted."
- message:message
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:errorTitle
+ message:errorMsg
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"CLOSE", @"CLOSE")
+ NSString *closeBtnLabel = PGM_LOCALIZATION(@"CLOSE_BUTTON", nil);
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:closeBtnLabel
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action)
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^[a-zA-Z0-9$@$!%*?&#^-_.\\s+]+$" options:NSRegularExpressionCaseInsensitive error:nil];
if ([regex numberOfMatchesInString:CFBundleExecutable options:0 range:NSMakeRange(0, CFBundleExecutable.length)] == 0) {
- NSString *message = [NSString stringWithFormat:@"Google Maps SDK for iOS crashes with app name '%@'.\nCheck out the comment in the CordovaGoogleMaps.m file.", CFBundleExecutable];
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"[action required]"
- message:message
+ NSString *APP_NAME_ERROR_TITLE = PGM_LOCALIZATION(@"APP_NAME_ERROR_TITLE", nil);
+ NSString *APP_NAME_ERROR_MESSAGE = PGM_LOCALIZATION(@"APP_NAME_ERROR_MESSAGE", nil);
+
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:APP_NAME_ERROR_TITLE
+ message:APP_NAME_ERROR_MESSAGE
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"CLOSE", @"CLOSE")
+ NSString *closeBtnLabel = PGM_LOCALIZATION(@"CLOSE_BUTTON", nil);
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:closeBtnLabel
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action)
{

MODIFY
src/ios/GoogleMaps/PluginLocationService.h
src/ios/GoogleMaps/PluginLocationService.h
#import <Cordova/CDV.h>
#import <GoogleMaps/GoogleMaps.h>
+#import "PluginUtil.h"
@interface PluginLocationService : CDVPlugin<CLLocationManagerDelegate>

MODIFY
src/ios/GoogleMaps/PluginLocationService.m
src/ios/GoogleMaps/PluginLocationService.m
// kCLAuthorizationStatusDenied
// kCLAuthorizationStatusRestricted
//----------------------------------------------------
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Location Services disabled"
- message:@"This app needs access to your location. Please turn on Location Services in your device settings."
+ NSString *LOCAITON_IS_UNAVAILABLE_ERROR_TITLE = PGM_LOCALIZATION(@"LOCAITON_IS_UNAVAILABLE_ERROR_TITLE", nil);
+ NSString *LOCAITON_IS_UNAVAILABLE_ERROR_MESSAGE = PGM_LOCALIZATION(@"LOCAITON_IS_UNAVAILABLE_ERROR_MESSAGE", nil);
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:LOCAITON_IS_UNAVAILABLE_ERROR_TITLE
+ message:LOCAITON_IS_UNAVAILABLE_ERROR_MESSAGE
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"CLOSE", @"CLOSE")
+ NSString *closeBtnLabel = PGM_LOCALIZATION(@"CLOSE_BUTTON", nil);
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:closeBtnLabel
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action)
{
NSString *error_code = @"service_denied";
- NSString *error_message = @"This app has rejected to use Location Services.";
+ NSString *error_message = PGM_LOCALIZATION(@"LOCAITON_IS_DENIED_MESSAGE", nil);
NSMutableDictionary *json = [NSMutableDictionary dictionary];
[json setObject:[NSNumber numberWithBool:NO] forKey:@"status"];
NSMutableDictionary *json = [NSMutableDictionary dictionary];
[json setObject:[NSNumber numberWithBool:NO] forKey:@"status"];
NSString *error_code = @"error";
- NSString *error_message = @"Cannot get your location.";
+ NSString *error_message = PGM_LOCALIZATION(@"CAN_NOT_GET_LOCATION_MESSAGE", nil);
[json setObject:[NSString stringWithString:error_message] forKey:@"error_message"];
[json setObject:[NSString stringWithString:error_code] forKey:@"error_code"];
NSMutableDictionary *json = [NSMutableDictionary dictionary];
[json setObject:[NSNumber numberWithBool:NO] forKey:@"status"];
NSString *error_code = @"error";
- NSString *error_message = @"Cannot get your location.";
+ NSString *error_message = PGM_LOCALIZATION(@"CAN_NOT_GET_LOCATION_MESSAGE", nil);
if (error.code == kCLErrorDenied) {
error_code = @"service_denied";
- error_message = @"This app has rejected to use Location Services.";
+ error_message = PGM_LOCALIZATION(@"LOCATION_REJECTED_BY_USER_MESSAGE", nil);
}
[json setObject:[NSString stringWithString:error_message] forKey:@"error_message"];

MODIFY
src/ios/GoogleMaps/PluginUtil.h
src/ios/GoogleMaps/PluginUtil.h
#import <Cordova/CDVCommandDelegate.h>
#import <Cordova/CDVCommandDelegateImpl.h>
+#define PGM_LOCALIZATION(key, comment) \
+ [[[NSBundle mainBundle] localizedStringForKey:(key) value:(comment) table:nil] isEqualToString:(key)] ? \
+ [[NSBundle mainBundle] localizedStringForKey:(key) value:(comment) table:nil] : \
+ [[NSBundle mainBundle] localizedStringForKey:(key) value:(comment) table:@"pgm_Localizable"]
+
typedef void (^MYCompletionHandler)(NSError *error);
// Switch statement in Objective-C

ADD
src/ios/strings/Base.lproj/pgm_Localizable.strings
+NSLocationWhenInUseUsageDescription = "This app needs this permission to obtain your location.";
+NSLocationAlwaysUsageDescription = "This app needs this permission to follow your location.";
+
+/*
+ * Generic
+ */
+"CLOSE_BUTTON" = "CLOSE";
+
+/*
+ * CordovaGoogleMaps.m
+ */
+"APIKEY_IS_UNDEFINED_TITLE" = "API key error";
+"APIKEY_IS_UNDEFINED_MESSAGE" = "The variable 'API_KEY_FOR_IOS' is not registered.";
+
+"APP_NAME_ERROR_TITLE" = "You need to change the config.xml file";
+"APP_NAME_ERROR_MESSAGE" = "Google Maps SDK for iOS crashes if CFBundleExecutable contains non-English characters.\nMore details, Check out the comment in the CordovaGoogleMaps.m file.";
+
+/*
+ * PluginLocationService.m
+ */
+"LOCAITON_IS_UNAVAILABLE_ERROR_TITLE" = "Location Service is not available";
+"LOCAITON_IS_UNAVAILABLE_ERROR_MESSAGE" = "This app needs to access your location. Please turn on 'Settings > Privacy > Location Services'";
+
+"LOCAITON_IS_DENIED_MESSAGE" = "This app has rejected to use Location Services.";
+"CAN_NOT_GET_LOCATION_MESSAGE" = "Cannot get your location.";
+"LOCATION_REJECTED_BY_USER_MESSAGE" = "Location service is rejected by user.";

Implement iOS localization code