[ 
https://issues.apache.org/jira/browse/CB-7102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14061214#comment-14061214
 ] 

ASF GitHub Bot commented on CB-7102:
------------------------------------

Github user rodms10 commented on a diff in the pull request:

    
https://github.com/apache/cordova-plugin-globalization/pull/17#discussion_r14902768
  
    --- Diff: src/firefoxos/GlobalizationProxy.js ---
    @@ -0,0 +1,214 @@
    +/*
    + *
    + * 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 GlobalizationError = require('./GlobalizationError');
    +
    +
    +function addLinkToLocales() {
    +  // Adding globalization file to the HEAD section
    +  // <link rel="resource" type="application/l10n" href="locales/date.ini" 
/>
    +   var link = document.createElement("link");
    +   link.setAttribute("rel", "resource");
    +   link.setAttribute("type", "application/l10n");
    +   link.setAttribute("href", "locales/date.ini");
    +
    +   document.head.appendChild(link);
    +}
    +
    +addLinkToLocales();
    +
    +
    +function getPreferredLanguage(successCB, errorCB) {
    +    // WARNING: this isn't perfect - there is a difference between UI 
language
    +    // and preferred language, however it doesn't happen too often.
    +    navigator.mozL10n.ready(function() {
    +      successCB({value: navigator.mozL10n.language.code});
    +    });
    +}
    +
    +function getLocaleName(successCB, errorCB) {
    +    navigator.mozL10n.ready(function() {
    +      successCB(navigator.mozL10n.language.code);
    +    });
    +}
    +
    +function dateToString(successCB, errorCB, params) {
    +    var date = new Date(params[0].date);
    +    var options = params[0].options;
    +
    +    navigator.mozL10n.ready(function() {
    +      var f = new navigator.mozL10n.DateTimeFormat();
    +      successCB({'value': _getStringFromDate(f, date, options)});
    +    });
    +
    +    function _getStringFromDate(f, date, options) {
    +        var format = navigator.mozL10n.get('shortDateTimeFormat');
    +        if (options) {
    +          if (options.selector == 'date') {
    +            return f.localeDateString(date);
    +          }
    +          if (options.selector == 'time') {
    +            return f.localeTimeString(date);
    +          }
    +          if (options.formatLength != 'short') {
    +            var format = navigator.mozL10n.get('dateTimeFormat');
    +            return f.localeString(date, format);
    +          }
    +          if (options.selector == 'time') {
    +            return f.localeTimeString(date, format);
    +          }
    +        }
    +        var d = f.localeDateString(date);
    +        var t = f.localeTimeString(date);
    +        return d + ' ' + t;
    +    }
    +}
    +
    +function stringToDate(successCB, errorCB, params) {
    +    var date;
    +    var dateString = params[0].dateString;
    +    var options = params[0].options;
    +    try {
    +      date = new Date(dateString);
    +    } catch(e) {  
    +      console.log("Cordova, stringToDate, An error occurred " + e.message);
    +      return errorCB(GlobalizationError(
    +            GlobalizationError.PARSING_ERROR, e.message));
    +    } 
    +    if (!date || date == 'Invalid Date') {
    +      console.log("Cordova, stringToDate, Invalid Date: " + dateString);
    +      return errorCB(GlobalizationError(
    +            GlobalizationError.PARSING_ERROR, 'Invalid Date (' + 
dateString + ')'));
    +    }
    +
    +    var dateObj = {
    +      'year': date.getFullYear(),
    +      'month': date.getMonth(),
    +      'day': date.getDay() 
    +    };
    +    var timeObj = {
    +      'hour': date.getHours(),
    +      'minute': date.getMinutes(),
    +      'second': date.getSeconds(),
    +      'millisecond': date.getMilliseconds() 
    +    };
    +    if (options) {
    +      if (options.selector == 'date') {
    +        return successCB(dateObj);
    +      }
    +      if (options.selector == 'time') {
    +        return successCB(timeObj);
    +      }
    +    }
    +    for (var i in timeObj) {
    +      if (timeObj.hasOwnProperty(i)) {
    +        dateObj[i] = timeObj[i];
    +      }
    +    }
    +    successCB(dateObj);
    +}
    +
    +function getDatePattern(successCB, failureCB, options) {
    +    failureCB(GlobalizationError.UNKNOWN_ERROR, 'unsupported');
    +}
    +
    +function getDateNames(successCB, failureCB, params) {
    +  navigator.mozL10n.ready(function() {
    +    var version = 'long';
    +    var item = 'month';
    +    var first = 0;
    +    var options = params[0].options;
    +    if (options) {
    +      if (options.type == 'narrow') {
    +        version = 'short';
    +      } else if (options.type == 'genitive' && options.item == 'months') {
    --- End diff --
    
    Valid types for cordova are `wide` and `narrow`. Since `long` is the 
default, you can get rid of this else if altogether.


> globalization
> -------------
>
>                 Key: CB-7102
>                 URL: https://issues.apache.org/jira/browse/CB-7102
>             Project: Apache Cordova
>          Issue Type: Sub-task
>          Components: FirefoxOS
>            Reporter: Piotr Zalewa
>            Assignee: Piotr Zalewa
>
> Add globalization support for Firefox OS



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to