You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2013/05/31 00:44:02 UTC

[1/3] git commit: added native iOS files

Updated Branches:
  refs/heads/master 87286a2e0 -> a4aa44de9


added native iOS files


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/49ecf5ce
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/49ecf5ce
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/49ecf5ce

Branch: refs/heads/master
Commit: 49ecf5ce70aae167eca06a51009498d5fcab0d64
Parents: 87286a2
Author: hermwong <he...@gmail.com>
Authored: Thu May 30 15:42:25 2013 -0700
Committer: hermwong <he...@gmail.com>
Committed: Thu May 30 15:42:25 2013 -0700

----------------------------------------------------------------------
 src/ios/CDVGlobalization.h |  150 ++++++++
 src/ios/CDVGlobalization.m |  790 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 940 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/49ecf5ce/src/ios/CDVGlobalization.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVGlobalization.h b/src/ios/CDVGlobalization.h
new file mode 100644
index 0000000..0384656
--- /dev/null
+++ b/src/ios/CDVGlobalization.h
@@ -0,0 +1,150 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVPlugin.h"
+
+#define CDV_FORMAT_SHORT 0
+#define CDV_FORMAT_MEDIUM 1
+#define CDV_FORMAT_LONG 2
+#define CDV_FORMAT_FULL 3
+#define CDV_SELECTOR_MONTHS 0
+#define CDV_SELECTOR_DAYS 1
+
+enum CDVGlobalizationError {
+    CDV_UNKNOWN_ERROR = 0,
+    CDV_FORMATTING_ERROR = 1,
+    CDV_PARSING_ERROR = 2,
+    CDV_PATTERN_ERROR = 3,
+};
+typedef NSUInteger CDVGlobalizationError;
+
+@interface CDVGlobalization : CDVPlugin {
+    CFLocaleRef currentLocale;
+}
+
+- (void)getPreferredLanguage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns the string identifier for the clients current locale setting.
+ * It returns the locale identifier string to the successCB callback with a
+ * properties object as a parameter. If there is an error getting the locale,
+ * then the errorCB callback is invoked.
+ */
+- (void)getLocaleName:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns a date formatted as a string according to the clients user preferences and
+ * calendar using the time zone of the client. It returns the formatted date string to the
+ * successCB callback with a properties object as a parameter. If there is an error
+ * formatting the date, then the errorCB callback is invoked.
+ *
+ * options: "date" contains the number of milliseconds that represents the JavaScript date
+ */
+- (void)dateToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Parses a date formatted as a string according to the clients user
+ * preferences and calendar using the time zone of the client and returns
+ * the corresponding date object. It returns the date to the successCB
+ * callback with a properties object as a parameter. If there is an error
+ * parsing the date string, then the errorCB callback is invoked.
+ *
+ * options: "dateString" contains the JavaScript string to parse for a date
+ */
+- (void)stringToDate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns a pattern string for formatting and parsing dates according to the clients
+ * user preferences. It returns the pattern to the successCB callback with a
+ * properties object as a parameter. If there is an error obtaining the pattern,
+ * then the errorCB callback is invoked.
+ *
+ */
+- (void)getDatePattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns an array of either the names of the months or days of the week
+ * according to the clients user preferences and calendar. It returns the array of names to the
+ * successCB callback with a properties object as a parameter. If there is an error obtaining the
+ * names, then the errorCB callback is invoked.
+ *
+ */
+- (void)getDateNames:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns whether daylight savings time is in effect for a given date using the clients
+ * time zone and calendar. It returns whether or not daylight savings time is in effect
+ * to the successCB callback with a properties object as a parameter. If there is an error
+ * reading the date, then the errorCB callback is invoked.
+ *
+ * options: "date" contains the number of milliseconds that represents the JavaScript date
+ *
+ */
+- (void)isDayLightSavingsTime:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns the first day of the week according to the clients user preferences and calendar.
+ * The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
+ * It returns the day to the successCB callback with a properties object as a parameter.
+ * If there is an error obtaining the pattern, then the errorCB callback is invoked.
+ *
+ */
+- (void)getFirstDayOfWeek:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns a number formatted as a string according to the clients user preferences.
+ * It returns the formatted number string to the successCB callback with a properties object as a
+ * parameter. If there is an error formatting the number, then the errorCB callback is invoked.
+ *
+ * options: "number" contains the JavaScript number to format
+ *
+ */
+- (void)numberToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Parses a number formatted as a string according to the clients user preferences and
+ * returns the corresponding number. It returns the number to the successCB callback with a
+ * properties object as a parameter. If there is an error parsing the number string, then
+ * the errorCB callback is invoked.
+ *
+ * options: "numberString" contains the JavaScript string to parse for a number
+ *
+ */
+- (void)stringToNumber:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns a pattern string for formatting and parsing numbers according to the clients user
+ * preferences. It returns the pattern to the successCB callback with a properties object as a
+ * parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
+ *
+ */
+- (void)getNumberPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+/**
+ * Returns a pattern string for formatting and parsing currency values according to the clients
+ * user preferences and ISO 4217 currency code. It returns the pattern to the successCB callback with a
+ * properties object as a parameter. If there is an error obtaining the pattern, then the errorCB
+ * callback is invoked.
+ *
+ * options: "currencyCode" contains the ISO currency code from JavaScript
+ */
+- (void)getCurrencyPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/49ecf5ce/src/ios/CDVGlobalization.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVGlobalization.m b/src/ios/CDVGlobalization.m
new file mode 100644
index 0000000..9eb9721
--- /dev/null
+++ b/src/ios/CDVGlobalization.m
@@ -0,0 +1,790 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVGlobalization.h"
+
+@implementation CDVGlobalization
+
+- (id)initWithWebView:(UIWebView*)theWebView
+{
+    self = (CDVGlobalization*)[super initWithWebView:theWebView];
+    if (self) {
+        currentLocale = CFLocaleCopyCurrent();
+    }
+    return self;
+}
+
+- (void)getPreferredLanguage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    NSString* callbackId = [arguments objectAtIndex:0];
+    CDVPluginResult* result = nil;
+
+    NSLog(@"log1");
+    // Source: http://stackoverflow.com/questions/3910244/getting-current-device-language-in-ios
+    // (should be OK)
+    NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
+
+    if (language) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:language forKey:@"value"];
+
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+                               messageAsDictionary:dictionary];
+    } else {
+        // TBD is this ever expected to happen?
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_UNKNOWN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unknown error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+}
+
+- (void)getLocaleName:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callbackId = [arguments objectAtIndex:0];
+    NSDictionary* dictionary = nil;
+
+    NSLocale* locale = [NSLocale currentLocale];
+
+    if (locale) {
+        dictionary = [NSDictionary dictionaryWithObject:[locale localeIdentifier] forKey:@"value"];
+
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    } else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_UNKNOWN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unknown error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+}
+
+- (void)dateToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CFDateFormatterStyle style = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle timeStyle = kCFDateFormatterShortStyle;
+    NSDate* date = nil;
+    NSString* dateString = nil;
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+
+    id milliseconds = [options valueForKey:@"date"];
+
+    if (milliseconds && [milliseconds isKindOfClass:[NSNumber class]]) {
+        // get the number of seconds since 1970 and create the date object
+        date = [NSDate dateWithTimeIntervalSince1970:[milliseconds doubleValue] / 1000];
+    }
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired format length
+                if ([key isEqualToString:@"formatLength"]) {
+                    if ([item isEqualToString:@"short"]) {
+                        style = kCFDateFormatterShortStyle;
+                    } else if ([item isEqualToString:@"medium"]) {
+                        style = kCFDateFormatterMediumStyle;
+                    } else if ([item isEqualToString:@"long"]) {
+                        style = kCFDateFormatterLongStyle;
+                    } else if ([item isEqualToString:@"full"]) {
+                        style = kCFDateFormatterFullStyle;
+                    }
+                }
+                // get the type of date and time to generate
+                else if ([key isEqualToString:@"selector"]) {
+                    if ([item isEqualToString:@"date"]) {
+                        dateStyle = style;
+                        timeStyle = kCFDateFormatterNoStyle;
+                    } else if ([item isEqualToString:@"time"]) {
+                        dateStyle = kCFDateFormatterNoStyle;
+                        timeStyle = style;
+                    } else if ([item isEqualToString:@"date and time"]) {
+                        dateStyle = style;
+                        timeStyle = style;
+                    }
+                }
+            }
+        }
+    }
+
+    // create the formatter using the user's current default locale and formats for dates and times
+    CFDateFormatterRef formatter = CFDateFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            dateStyle,
+            timeStyle);
+    // if we have a valid date object then call the formatter
+    if (date) {
+        dateString = (__bridge_transfer NSString*)CFDateFormatterCreateStringWithDate(kCFAllocatorDefault,
+                formatter,
+                (__bridge CFDateRef)date);
+    }
+
+    // if the date was converted to a string successfully then return the result
+    if (dateString) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:dateString forKey:@"value"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        // DLog(@"GlobalizationCommand dateToString unable to format %@", [date description]);
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_FORMATTING_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Formatting error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)stringToDate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CFDateFormatterStyle style = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle timeStyle = kCFDateFormatterShortStyle;
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+    NSString* dateString = nil;
+    NSDateComponents* comps = nil;
+
+    // get the string that is to be parsed for a date
+    id ms = [options valueForKey:@"dateString"];
+
+    if (ms && [ms isKindOfClass:[NSString class]]) {
+        dateString = ms;
+    }
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired format length
+                if ([key isEqualToString:@"formatLength"]) {
+                    if ([item isEqualToString:@"short"]) {
+                        style = kCFDateFormatterShortStyle;
+                    } else if ([item isEqualToString:@"medium"]) {
+                        style = kCFDateFormatterMediumStyle;
+                    } else if ([item isEqualToString:@"long"]) {
+                        style = kCFDateFormatterLongStyle;
+                    } else if ([item isEqualToString:@"full"]) {
+                        style = kCFDateFormatterFullStyle;
+                    }
+                }
+                // get the type of date and time to generate
+                else if ([key isEqualToString:@"selector"]) {
+                    if ([item isEqualToString:@"date"]) {
+                        dateStyle = style;
+                        timeStyle = kCFDateFormatterNoStyle;
+                    } else if ([item isEqualToString:@"time"]) {
+                        dateStyle = kCFDateFormatterNoStyle;
+                        timeStyle = style;
+                    } else if ([item isEqualToString:@"date and time"]) {
+                        dateStyle = style;
+                        timeStyle = style;
+                    }
+                }
+            }
+        }
+    }
+
+    // get the user's default settings for date and time formats
+    CFDateFormatterRef formatter = CFDateFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            dateStyle,
+            timeStyle);
+
+    // set the parsing to be more lenient
+    CFDateFormatterSetProperty(formatter, kCFDateFormatterIsLenient, kCFBooleanTrue);
+
+    // parse tha date and time string
+    CFDateRef date = CFDateFormatterCreateDateFromString(kCFAllocatorDefault,
+            formatter,
+            (__bridge CFStringRef)dateString,
+            NULL);
+
+    // if we were able to parse the date then get the date and time components
+    if (date != NULL) {
+        NSCalendar* calendar = [NSCalendar currentCalendar];
+
+        unsigned unitFlags = NSYearCalendarUnit |
+            NSMonthCalendarUnit |
+            NSDayCalendarUnit |
+            NSHourCalendarUnit |
+            NSMinuteCalendarUnit |
+            NSSecondCalendarUnit;
+
+        comps = [calendar components:unitFlags fromDate:(__bridge NSDate*)date];
+        CFRelease(date);
+    }
+
+    // put the various elements of the date and time into a dictionary
+    if (comps != nil) {
+        NSArray* keys = [NSArray arrayWithObjects:@"year", @"month", @"day", @"hour", @"minute", @"second", @"millisecond", nil];
+        NSArray* values = [NSArray arrayWithObjects:[NSNumber numberWithInt:[comps year]],
+            [NSNumber numberWithInt:[comps month] - 1],
+            [NSNumber numberWithInt:[comps day]],
+            [NSNumber numberWithInt:[comps hour]],
+            [NSNumber numberWithInt:[comps minute]],
+            [NSNumber numberWithInt:[comps second]],
+            [NSNumber numberWithInt:0],                /* iOS does not provide milliseconds */
+            nil];
+
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        // Dlog(@"GlobalizationCommand stringToDate unable to parse %@", dateString);
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_PARSING_ERROR] forKey:@"code"];
+        [dictionary setValue:@"unable to parse" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)getDatePattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CFDateFormatterStyle style = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
+    CFDateFormatterStyle timeStyle = kCFDateFormatterShortStyle;
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired format length
+                if ([key isEqualToString:@"formatLength"]) {
+                    if ([item isEqualToString:@"short"]) {
+                        style = kCFDateFormatterShortStyle;
+                    } else if ([item isEqualToString:@"medium"]) {
+                        style = kCFDateFormatterMediumStyle;
+                    } else if ([item isEqualToString:@"long"]) {
+                        style = kCFDateFormatterLongStyle;
+                    } else if ([item isEqualToString:@"full"]) {
+                        style = kCFDateFormatterFullStyle;
+                    }
+                }
+                // get the type of date and time to generate
+                else if ([key isEqualToString:@"selector"]) {
+                    if ([item isEqualToString:@"date"]) {
+                        dateStyle = style;
+                        timeStyle = kCFDateFormatterNoStyle;
+                    } else if ([item isEqualToString:@"time"]) {
+                        dateStyle = kCFDateFormatterNoStyle;
+                        timeStyle = style;
+                    } else if ([item isEqualToString:@"date and time"]) {
+                        dateStyle = style;
+                        timeStyle = style;
+                    }
+                }
+            }
+        }
+    }
+
+    // get the user's default settings for date and time formats
+    CFDateFormatterRef formatter = CFDateFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            dateStyle,
+            timeStyle);
+
+    // get the date pattern to apply when formatting and parsing
+    CFStringRef datePattern = CFDateFormatterGetFormat(formatter);
+    // get the user's current time zone information
+    CFTimeZoneRef timezone = (CFTimeZoneRef)CFDateFormatterCopyProperty(formatter, kCFDateFormatterTimeZone);
+
+    // put the pattern and time zone information into the dictionary
+    if ((datePattern != nil) && (timezone != nil)) {
+        NSArray* keys = [NSArray arrayWithObjects:@"pattern", @"timezone", @"utc_offset", @"dst_offset", nil];
+        NSArray* values = [NSArray arrayWithObjects:((__bridge NSString*)datePattern),
+            [((__bridge NSTimeZone*)timezone)abbreviation],
+            [NSNumber numberWithLong:[((__bridge NSTimeZone*)timezone)secondsFromGMT]],
+            [NSNumber numberWithDouble:[((__bridge NSTimeZone*)timezone)daylightSavingTimeOffset]],
+            nil];
+
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_PATTERN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Pattern error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    if (timezone) {
+        CFRelease(timezone);
+    }
+    CFRelease(formatter);
+}
+
+- (void)getDateNames:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    int style = CDV_FORMAT_LONG;
+    int selector = CDV_SELECTOR_MONTHS;
+    CFStringRef dataStyle = kCFDateFormatterMonthSymbols;
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired type of name
+                if ([key isEqualToString:@"type"]) {
+                    if ([item isEqualToString:@"narrow"]) {
+                        style = CDV_FORMAT_SHORT;
+                    } else if ([item isEqualToString:@"wide"]) {
+                        style = CDV_FORMAT_LONG;
+                    }
+                }
+                // determine if months or days are needed
+                else if ([key isEqualToString:@"item"]) {
+                    if ([item isEqualToString:@"months"]) {
+                        selector = CDV_SELECTOR_MONTHS;
+                    } else if ([item isEqualToString:@"days"]) {
+                        selector = CDV_SELECTOR_DAYS;
+                    }
+                }
+            }
+        }
+    }
+
+    CFDateFormatterRef formatter = CFDateFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            kCFDateFormatterFullStyle,
+            kCFDateFormatterFullStyle);
+
+    if ((selector == CDV_SELECTOR_MONTHS) && (style == CDV_FORMAT_LONG)) {
+        dataStyle = kCFDateFormatterMonthSymbols;
+    } else if ((selector == CDV_SELECTOR_MONTHS) && (style == CDV_FORMAT_SHORT)) {
+        dataStyle = kCFDateFormatterShortMonthSymbols;
+    } else if ((selector == CDV_SELECTOR_DAYS) && (style == CDV_FORMAT_LONG)) {
+        dataStyle = kCFDateFormatterWeekdaySymbols;
+    } else if ((selector == CDV_SELECTOR_DAYS) && (style == CDV_FORMAT_SHORT)) {
+        dataStyle = kCFDateFormatterShortWeekdaySymbols;
+    }
+
+    CFArrayRef names = (CFArrayRef)CFDateFormatterCopyProperty(formatter, dataStyle);
+
+    if (names) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:((__bridge NSArray*)names) forKey:@"value"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+        CFRelease(names);
+    }
+    // error
+    else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_UNKNOWN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unknown error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)isDayLightSavingsTime:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    NSDate* date = nil;
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+
+    id milliseconds = [options valueForKey:@"date"];
+
+    if (milliseconds && [milliseconds isKindOfClass:[NSNumber class]]) {
+        // get the number of seconds since 1970 and create the date object
+        date = [NSDate dateWithTimeIntervalSince1970:[milliseconds doubleValue] / 1000];
+    }
+
+    if (date) {
+        // get the current calendar for the user and check if the date is using DST
+        NSCalendar* calendar = [NSCalendar currentCalendar];
+        NSTimeZone* timezone = [calendar timeZone];
+        NSNumber* dst = [NSNumber numberWithBool:[timezone isDaylightSavingTimeForDate:date]];
+
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:dst forKey:@"dst"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_UNKNOWN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unknown error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+}
+
+- (void)getFirstDayOfWeek:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+
+    NSCalendar* calendar = [NSCalendar autoupdatingCurrentCalendar];
+
+    NSNumber* day = [NSNumber numberWithInt:[calendar firstWeekday]];
+
+    if (day) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:day forKey:@"value"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_UNKNOWN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unknown error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+}
+
+- (void)numberToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+    CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
+    NSNumber* number = nil;
+
+    id value = [options valueForKey:@"number"];
+
+    if (value && [value isKindOfClass:[NSNumber class]]) {
+        number = (NSNumber*)value;
+    }
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired style of formatting
+                if ([key isEqualToString:@"type"]) {
+                    if ([item isEqualToString:@"percent"]) {
+                        style = kCFNumberFormatterPercentStyle;
+                    } else if ([item isEqualToString:@"currency"]) {
+                        style = kCFNumberFormatterCurrencyStyle;
+                    } else if ([item isEqualToString:@"decimal"]) {
+                        style = kCFNumberFormatterDecimalStyle;
+                    }
+                }
+            }
+        }
+    }
+
+    CFNumberFormatterRef formatter = CFNumberFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            style);
+
+    // get the localized string based upon the locale and user preferences
+    NSString* numberString = (__bridge_transfer NSString*)CFNumberFormatterCreateStringWithNumber(kCFAllocatorDefault,
+            formatter,
+            (__bridge CFNumberRef)number);
+
+    if (numberString) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:numberString forKey:@"value"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        // DLog(@"GlobalizationCommand numberToString unable to format %@", [number stringValue]);
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_FORMATTING_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unable to format" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)stringToNumber:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+    CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
+    NSString* numberString = nil;
+    double doubleValue;
+
+    id value = [options valueForKey:@"numberString"];
+
+    if (value && [value isKindOfClass:[NSString class]]) {
+        numberString = (NSString*)value;
+    }
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired style of formatting
+                if ([key isEqualToString:@"type"]) {
+                    if ([item isEqualToString:@"percent"]) {
+                        style = kCFNumberFormatterPercentStyle;
+                    } else if ([item isEqualToString:@"currency"]) {
+                        style = kCFNumberFormatterCurrencyStyle;
+                    } else if ([item isEqualToString:@"decimal"]) {
+                        style = kCFNumberFormatterDecimalStyle;
+                    }
+                }
+            }
+        }
+    }
+
+    CFNumberFormatterRef formatter = CFNumberFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            style);
+
+    // we need to make this lenient so as to avoid problems with parsing currencies that have non-breaking space characters
+    if (style == kCFNumberFormatterCurrencyStyle) {
+        CFNumberFormatterSetProperty(formatter, kCFNumberFormatterIsLenient, kCFBooleanTrue);
+    }
+
+    // parse againist the largest type to avoid data loss
+    Boolean rc = CFNumberFormatterGetValueFromString(formatter,
+            (__bridge CFStringRef)numberString,
+            NULL,
+            kCFNumberDoubleType,
+            &doubleValue);
+
+    if (rc) {
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithDouble:doubleValue] forKey:@"value"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        // DLog(@"GlobalizationCommand stringToNumber unable to parse %@", numberString);
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_PARSING_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unable to parse" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)getNumberPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+    CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
+    CFStringRef symbolType = NULL;
+    NSString* symbol = @"";
+
+    // see if any options have been specified
+    id items = [options valueForKey:@"options"];
+
+    if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
+        NSEnumerator* enumerator = [items keyEnumerator];
+        id key;
+
+        // iterate through all the options
+        while ((key = [enumerator nextObject])) {
+            id item = [items valueForKey:key];
+
+            // make sure that only string values are present
+            if ([item isKindOfClass:[NSString class]]) {
+                // get the desired style of formatting
+                if ([key isEqualToString:@"type"]) {
+                    if ([item isEqualToString:@"percent"]) {
+                        style = kCFNumberFormatterPercentStyle;
+                    } else if ([item isEqualToString:@"currency"]) {
+                        style = kCFNumberFormatterCurrencyStyle;
+                    } else if ([item isEqualToString:@"decimal"]) {
+                        style = kCFNumberFormatterDecimalStyle;
+                    }
+                }
+            }
+        }
+    }
+
+    CFNumberFormatterRef formatter = CFNumberFormatterCreate(kCFAllocatorDefault,
+            currentLocale,
+            style);
+
+    NSString* numberPattern = (__bridge NSString*)CFNumberFormatterGetFormat(formatter);
+
+    if (style == kCFNumberFormatterCurrencyStyle) {
+        symbolType = kCFNumberFormatterCurrencySymbol;
+    } else if (style == kCFNumberFormatterPercentStyle) {
+        symbolType = kCFNumberFormatterPercentSymbol;
+    }
+
+    if (symbolType) {
+        symbol = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, symbolType);
+    }
+
+    NSString* decimal = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterDecimalSeparator);
+    NSString* grouping = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterGroupingSeparator);
+    NSString* posSign = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterPlusSign);
+    NSString* negSign = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterMinusSign);
+    NSNumber* fracDigits = (__bridge_transfer NSNumber*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterMinFractionDigits);
+    NSNumber* roundingDigits = (__bridge_transfer NSNumber*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterRoundingIncrement);
+
+    // put the pattern information into the dictionary
+    if (numberPattern != nil) {
+        NSArray* keys = [NSArray arrayWithObjects:@"pattern", @"symbol", @"fraction", @"rounding",
+            @"positive", @"negative", @"decimal", @"grouping", nil];
+        NSArray* values = [NSArray arrayWithObjects:numberPattern, symbol, fracDigits, roundingDigits,
+            posSign, negSign, decimal, grouping, nil];
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+    }
+    // error
+    else {
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_PATTERN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Pattern error" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+
+    CFRelease(formatter);
+}
+
+- (void)getCurrencyPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+    CDVPluginResult* result = nil;
+    NSString* callBackId = [arguments objectAtIndex:0];
+    NSString* currencyCode = nil;
+    NSString* numberPattern = nil;
+    NSString* decimal = nil;
+    NSString* grouping = nil;
+    int32_t defaultFractionDigits;
+    double roundingIncrement;
+    Boolean rc;
+
+    id value = [options valueForKey:@"currencyCode"];
+
+    if (value && [value isKindOfClass:[NSString class]]) {
+        currencyCode = (NSString*)value;
+    }
+
+    // first see if there is base currency info available and fill in the currency_info structure
+    rc = CFNumberFormatterGetDecimalInfoForCurrencyCode((__bridge CFStringRef)currencyCode, &defaultFractionDigits, &roundingIncrement);
+
+    // now set the currency code in the formatter
+    if (rc) {
+        CFNumberFormatterRef formatter = CFNumberFormatterCreate(kCFAllocatorDefault,
+                currentLocale,
+                kCFNumberFormatterCurrencyStyle);
+
+        CFNumberFormatterSetProperty(formatter, kCFNumberFormatterCurrencyCode, (__bridge CFStringRef)currencyCode);
+        CFNumberFormatterSetProperty(formatter, kCFNumberFormatterInternationalCurrencySymbol, (__bridge CFStringRef)currencyCode);
+
+        numberPattern = (__bridge NSString*)CFNumberFormatterGetFormat(formatter);
+        decimal = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterCurrencyDecimalSeparator);
+        grouping = (__bridge_transfer NSString*)CFNumberFormatterCopyProperty(formatter, kCFNumberFormatterCurrencyGroupingSeparator);
+
+        NSArray* keys = [NSArray arrayWithObjects:@"pattern", @"code", @"fraction", @"rounding",
+            @"decimal", @"grouping", nil];
+        NSArray* values = [NSArray arrayWithObjects:numberPattern, currencyCode, [NSNumber numberWithInt:defaultFractionDigits],
+            [NSNumber numberWithDouble:roundingIncrement], decimal, grouping, nil];
+        NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
+        CFRelease(formatter);
+    }
+    // error
+    else {
+        // DLog(@"GlobalizationCommand getCurrencyPattern unable to get pattern for %@", currencyCode);
+        NSMutableDictionary* dictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [dictionary setValue:[NSNumber numberWithInt:CDV_PATTERN_ERROR] forKey:@"code"];
+        [dictionary setValue:@"Unable to get pattern" forKey:@"message"];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
+    }
+
+    [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+}
+
+- (void)dealloc
+{
+    if (currentLocale) {
+        CFRelease(currentLocale);
+        currentLocale = nil;
+    }
+}
+
+@end


[2/3] git commit: added Cordova-JS files

Posted by he...@apache.org.
added Cordova-JS files


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/8a595ebc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/8a595ebc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/8a595ebc

Branch: refs/heads/master
Commit: 8a595ebc55aed11eacc91d3caa79f8622956a8be
Parents: 49ecf5c
Author: hermwong <he...@gmail.com>
Authored: Thu May 30 15:42:55 2013 -0700
Committer: hermwong <he...@gmail.com>
Committed: Thu May 30 15:42:55 2013 -0700

----------------------------------------------------------------------
 www/GlobalizationError.js |   41 +++++
 www/globalization.js      |  391 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 432 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/8a595ebc/www/GlobalizationError.js
----------------------------------------------------------------------
diff --git a/www/GlobalizationError.js b/www/GlobalizationError.js
new file mode 100644
index 0000000..d2dcced
--- /dev/null
+++ b/www/GlobalizationError.js
@@ -0,0 +1,41 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+/**
+ * Globalization error object
+ *
+ * @constructor
+ * @param code
+ * @param message
+ */
+var GlobalizationError = function(code, message) {
+    this.code = code || null;
+    this.message = message || '';
+};
+
+// Globalization error codes
+GlobalizationError.UNKNOWN_ERROR = 0;
+GlobalizationError.FORMATTING_ERROR = 1;
+GlobalizationError.PARSING_ERROR = 2;
+GlobalizationError.PATTERN_ERROR = 3;
+
+module.exports = GlobalizationError;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/8a595ebc/www/globalization.js
----------------------------------------------------------------------
diff --git a/www/globalization.js b/www/globalization.js
new file mode 100644
index 0000000..2a1c854
--- /dev/null
+++ b/www/globalization.js
@@ -0,0 +1,391 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var argscheck = require('cordova/argscheck'),
+    exec = require('cordova/exec'),
+    GlobalizationError = require('cordova/plugin/GlobalizationError');
+
+var globalization = {
+
+/**
+* Returns the string identifier for the client's current language.
+* It returns the language identifier string to the successCB callback with a
+* properties object as a parameter. If there is an error getting the language,
+* then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {String}: The language identifier
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+*    globalization.getPreferredLanguage(function (language) {alert('language:' + language.value + '\n');},
+*                                function () {});
+*/
+getPreferredLanguage:function(successCB, failureCB) {
+    argscheck.checkArgs('fF', 'Globalization.getPreferredLanguage', arguments);
+    exec(successCB, failureCB, "Globalization","getPreferredLanguage", []);
+},
+
+/**
+* Returns the string identifier for the client's current locale setting.
+* It returns the locale identifier string to the successCB callback with a
+* properties object as a parameter. If there is an error getting the locale,
+* then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {String}: The locale identifier
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+*    globalization.getLocaleName(function (locale) {alert('locale:' + locale.value + '\n');},
+*                                function () {});
+*/
+getLocaleName:function(successCB, failureCB) {
+    argscheck.checkArgs('fF', 'Globalization.getLocaleName', arguments);
+    exec(successCB, failureCB, "Globalization","getLocaleName", []);
+},
+
+
+/**
+* Returns a date formatted as a string according to the client's user preferences and
+* calendar using the time zone of the client. It returns the formatted date string to the
+* successCB callback with a properties object as a parameter. If there is an error
+* formatting the date, then the errorCB callback is invoked.
+*
+* The defaults are: formatLenght="short" and selector="date and time"
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            formatLength {String}: 'short', 'medium', 'long', or 'full'
+*            selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.value {String}: The localized date string
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+*    globalization.dateToString(new Date(),
+*                function (date) {alert('date:' + date.value + '\n');},
+*                function (errorCode) {alert(errorCode);},
+*                {formatLength:'short'});
+*/
+dateToString:function(date, successCB, failureCB, options) {
+    argscheck.checkArgs('dfFO', 'Globalization.dateToString', arguments);
+    var dateValue = date.valueOf();
+    exec(successCB, failureCB, "Globalization", "dateToString", [{"date": dateValue, "options": options}]);
+},
+
+
+/**
+* Parses a date formatted as a string according to the client's user
+* preferences and calendar using the time zone of the client and returns
+* the corresponding date object. It returns the date to the successCB
+* callback with a properties object as a parameter. If there is an error
+* parsing the date string, then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {String} dateString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            formatLength {String}: 'short', 'medium', 'long', or 'full'
+*            selector {String}: 'date', 'time', or 'date and time'
+*
+* @return    Object.year {Number}: The four digit year
+*            Object.month {Number}: The month from (0 - 11)
+*            Object.day {Number}: The day from (1 - 31)
+*            Object.hour {Number}: The hour from (0 - 23)
+*            Object.minute {Number}: The minute from (0 - 59)
+*            Object.second {Number}: The second from (0 - 59)
+*            Object.millisecond {Number}: The milliseconds (from 0 - 999),
+*                                        not available on all platforms
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+*    globalization.stringToDate('4/11/2011',
+*                function (date) { alert('Month:' + date.month + '\n' +
+*                    'Day:' + date.day + '\n' +
+*                    'Year:' + date.year + '\n');},
+*                function (errorCode) {alert(errorCode);},
+*                {selector:'date'});
+*/
+stringToDate:function(dateString, successCB, failureCB, options) {
+    argscheck.checkArgs('sfFO', 'Globalization.stringToDate', arguments);
+    exec(successCB, failureCB, "Globalization", "stringToDate", [{"dateString": dateString, "options": options}]);
+},
+
+
+/**
+* Returns a pattern string for formatting and parsing dates according to the client's
+* user preferences. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern,
+* then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            formatLength {String}: 'short', 'medium', 'long', or 'full'
+*            selector {String}: 'date', 'time', or 'date and time'
+*
+* @return    Object.pattern {String}: The date and time pattern for formatting and parsing dates.
+*                                    The patterns follow Unicode Technical Standard #35
+*                                    http://unicode.org/reports/tr35/tr35-4.html
+*            Object.timezone {String}: The abbreviated name of the time zone on the client
+*            Object.utc_offset {Number}: The current difference in seconds between the client's
+*                                        time zone and coordinated universal time.
+*            Object.dst_offset {Number}: The current daylight saving time offset in seconds
+*                                        between the client's non-daylight saving's time zone
+*                                        and the client's daylight saving's time zone.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+*    globalization.getDatePattern(
+*                function (date) {alert('pattern:' + date.pattern + '\n');},
+*                function () {},
+*                {formatLength:'short'});
+*/
+getDatePattern:function(successCB, failureCB, options) {
+    argscheck.checkArgs('fFO', 'Globalization.getDatePattern', arguments);
+    exec(successCB, failureCB, "Globalization", "getDatePattern", [{"options": options}]);
+},
+
+
+/**
+* Returns an array of either the names of the months or days of the week
+* according to the client's user preferences and calendar. It returns the array of names to the
+* successCB callback with a properties object as a parameter. If there is an error obtaining the
+* names, then the errorCB callback is invoked.
+*
+* The defaults are: type="wide" and item="months"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            type {String}: 'narrow' or 'wide'
+*            item {String}: 'months', or 'days'
+*
+* @return Object.value {Array{String}}: The array of names starting from either
+*                                        the first month in the year or the
+*                                        first day of the week.
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+*    globalization.getDateNames(function (names) {
+*        for(var i = 0; i < names.value.length; i++) {
+*            alert('Month:' + names.value[i] + '\n');}},
+*        function () {});
+*/
+getDateNames:function(successCB, failureCB, options) {
+    argscheck.checkArgs('fFO', 'Globalization.getDateNames', arguments);
+    exec(successCB, failureCB, "Globalization", "getDateNames", [{"options": options}]);
+},
+
+/**
+* Returns whether daylight savings time is in effect for a given date using the client's
+* time zone and calendar. It returns whether or not daylight savings time is in effect
+* to the successCB callback with a properties object as a parameter. If there is an error
+* reading the date, then the errorCB callback is invoked.
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.dst {Boolean}: The value "true" indicates that daylight savings time is
+*                                in effect for the given date and "false" indicate that it is not.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+*    globalization.isDayLightSavingsTime(new Date(),
+*                function (date) {alert('dst:' + date.dst + '\n');}
+*                function () {});
+*/
+isDayLightSavingsTime:function(date, successCB, failureCB) {
+    argscheck.checkArgs('dfF', 'Globalization.isDayLightSavingsTime', arguments);
+    var dateValue = date.valueOf();
+    exec(successCB, failureCB, "Globalization", "isDayLightSavingsTime", [{"date": dateValue}]);
+},
+
+/**
+* Returns the first day of the week according to the client's user preferences and calendar.
+* The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
+* It returns the day to the successCB callback with a properties object as a parameter.
+* If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {Number}: The number of the first day of the week.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+*    globalization.getFirstDayOfWeek(function (day)
+*                { alert('Day:' + day.value + '\n');},
+*                function () {});
+*/
+getFirstDayOfWeek:function(successCB, failureCB) {
+    argscheck.checkArgs('fF', 'Globalization.getFirstDayOfWeek', arguments);
+    exec(successCB, failureCB, "Globalization", "getFirstDayOfWeek", []);
+},
+
+
+/**
+* Returns a number formatted as a string according to the client's user preferences.
+* It returns the formatted number string to the successCB callback with a properties object as a
+* parameter. If there is an error formatting the number, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Number} number
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {String}: The formatted number string.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+*    globalization.numberToString(3.25,
+*                function (number) {alert('number:' + number.value + '\n');},
+*                function () {},
+*                {type:'decimal'});
+*/
+numberToString:function(number, successCB, failureCB, options) {
+    argscheck.checkArgs('nfFO', 'Globalization.numberToString', arguments);
+    exec(successCB, failureCB, "Globalization", "numberToString", [{"number": number, "options": options}]);
+},
+
+/**
+* Parses a number formatted as a string according to the client's user preferences and
+* returns the corresponding number. It returns the number to the successCB callback with a
+* properties object as a parameter. If there is an error parsing the number string, then
+* the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {String} numberString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {Number}: The parsed number.
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+*    globalization.stringToNumber('1234.56',
+*                function (number) {alert('Number:' + number.value + '\n');},
+*                function () { alert('Error parsing number');});
+*/
+stringToNumber:function(numberString, successCB, failureCB, options) {
+    argscheck.checkArgs('sfFO', 'Globalization.stringToNumber', arguments);
+    exec(successCB, failureCB, "Globalization", "stringToNumber", [{"numberString": numberString, "options": options}]);
+},
+
+/**
+* Returns a pattern string for formatting and parsing numbers according to the client's user
+* preferences. It returns the pattern to the successCB callback with a properties object as a
+* parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+*            type {String}: 'decimal', "percent", or 'currency'
+*
+* @return    Object.pattern {String}: The number pattern for formatting and parsing numbers.
+*                                    The patterns follow Unicode Technical Standard #35.
+*                                    http://unicode.org/reports/tr35/tr35-4.html
+*            Object.symbol {String}: The symbol to be used when formatting and parsing
+*                                    e.g., percent or currency symbol.
+*            Object.fraction {Number}: The number of fractional digits to use when parsing and
+*                                    formatting numbers.
+*            Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+*            Object.positive {String}: The symbol to use for positive numbers when parsing and formatting.
+*            Object.negative: {String}: The symbol to use for negative numbers when parsing and formatting.
+*            Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+*            Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+*    globalization.getNumberPattern(
+*                function (pattern) {alert('Pattern:' + pattern.pattern + '\n');},
+*                function () {});
+*/
+getNumberPattern:function(successCB, failureCB, options) {
+    argscheck.checkArgs('fFO', 'Globalization.getNumberPattern', arguments);
+    exec(successCB, failureCB, "Globalization", "getNumberPattern", [{"options": options}]);
+},
+
+/**
+* Returns a pattern string for formatting and parsing currency values according to the client's
+* user preferences and ISO 4217 currency code. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern, then the errorCB
+* callback is invoked.
+*
+* @param {String} currencyCode
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return    Object.pattern {String}: The currency pattern for formatting and parsing currency values.
+*                                    The patterns follow Unicode Technical Standard #35
+*                                    http://unicode.org/reports/tr35/tr35-4.html
+*            Object.code {String}: The ISO 4217 currency code for the pattern.
+*            Object.fraction {Number}: The number of fractional digits to use when parsing and
+*                                    formatting currency.
+*            Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+*            Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+*            Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+*    globalization.getCurrencyPattern('EUR',
+*                function (currency) {alert('Pattern:' + currency.pattern + '\n');}
+*                function () {});
+*/
+getCurrencyPattern:function(currencyCode, successCB, failureCB) {
+    argscheck.checkArgs('sfF', 'Globalization.getCurrencyPattern', arguments);
+    exec(successCB, failureCB, "Globalization", "getCurrencyPattern", [{"currencyCode": currencyCode}]);
+}
+
+};
+
+module.exports = globalization;


[3/3] git commit: added configuration for iOS files & JS files

Posted by he...@apache.org.
added configuration for iOS files & JS files


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/a4aa44de
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/a4aa44de
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/a4aa44de

Branch: refs/heads/master
Commit: a4aa44de9d465f1a4dfdaaae2be19014b3498d51
Parents: 8a595eb
Author: hermwong <he...@gmail.com>
Authored: Thu May 30 15:43:46 2013 -0700
Committer: hermwong <he...@gmail.com>
Committed: Thu May 30 15:43:46 2013 -0700

----------------------------------------------------------------------
 plugin.xml |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/a4aa44de/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 76e1b11..bc5abbd 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -2,10 +2,18 @@
 
 <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
 xmlns:android="http://schemas.android.com/apk/res/android"
-id="org.apache.cordova.core">
+id="org.apache.cordova.core.Globalization"
     version="0.1.0">
     <name>Globalization</name>
 
+    <js-module src="www/GlobalizationError.js" name="GlobalizationError">
+        <clobbers target="window.GlobalizationError" />
+    </js-module>
+    
+    <js-module src="www/globalization.js" name="globalization">
+        <clobbers target="navigator.globalization" />
+    </js-module>
+    
     <!-- android -->
     <platform name="android">
         <config-file target="res/xml/config.xml" parent="/cordova/plugins">
@@ -15,4 +23,16 @@ id="org.apache.cordova.core">
         <source-file src="Globalization.java" target-dir="org/apache/cordova/core" />
         <source-file src="GlobalizationError.java" target-dir="org/apache/cordova/core" />
        </platform>
+       
+       <!-- ios -->
+       <platform name="ios">    
+           <config-file target="config.xml" parent="/*">
+               <feature name="Globalization">
+                   <param name="ios-package" value="CDVGlobalization" /> 
+               </feature>
+           </config-file>
+           <header-file src="src/ios/CDVGlobalization.h" />
+           <source-file src="src/ios/CDVGlobalization.m" />
+       </platform>
+              
 </plugin>