Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh language file missing #1494

Closed
gdibble opened this issue Feb 25, 2014 · 8 comments
Closed

zh language file missing #1494

gdibble opened this issue Feb 25, 2014 · 8 comments

Comments

@gdibble
Copy link
Contributor

gdibble commented Feb 25, 2014

setting language to "Chinese [zh]" in firefox throws a ENOENT error in node when zh tries to require.

as far as i can tell, zn-ch == zn. (ref @ http://en.wikipedia.org/wiki/Wikipedia_talk:Chinese_interlanguage_links)

solution is to simply copy the zh-cn.js --> zh.js
(thus resulting in lang. being required and no server error.)


image

@icambron
Copy link
Member

icambron commented Mar 5, 2014

That Wikipedia talk page isn't very dispositive on that; it's mostly about how localization identifiers have been interchanged with character set identifiers, and I have no idea how that relates to the actual differences in the two Moment files. I think we need a bit more clarity on whether, in a geopolitical sense, making 'zh' return the current 'zh-cn' in the right thing to do. It makes sense and all, but it will be hard to undo, so I'd like to get some more opinions. CLDR does just have a single zh, so that's good.

The actual way to make the change is to rename the 'zh-cn' file to 'zh' and moment will do the right thing when the user requests 'zh-cn'.

@ichernev
Copy link
Contributor

How can setting the language in firefox throw an error in node? Are the tests failing, or moment website?

@gdibble
Copy link
Contributor Author

gdibble commented Mar 12, 2014

here are a few different implementations:

  1. On the [nodejs] server in a single-page app:
  var moment = require('moment');
  var defaultLang = 'en';
  var i18 = {}; //simplified for this gist
  if (req.acceptedLanguages.length) {
    i18.preferredCulture = req.acceptedLanguages[0];
  } else {
    i18.preferredCulture = defaultLang;
  }

  moment.lang(defaultLang);
   //if preferredCulture has a dash, try taking first portion: sets language if supported by moment, ignored if not supported
  if (i18.preferredCulture.indexOf('-') > -1) {
    moment.lang(i18.preferredCulture.split('-')[0]); //examples: 'en-GB' >>> 'en', 'tzm-la' >>> 'tzm'
  }
   //try preferredCulture directly, if not supported defaultLang (set above in Reset step) is used
  moment.lang(i18.preferredCulture.toLowerCase());
  1. On the client in a Backbone.js app: me.language is via the headers['Accept-Language'], i have a route that gets /lang/... from the moment node_modules dir.
    var lang = me.language[0].toLowerCase();

    if (lang !== 'en' && lang !== 'en-us') {
      $.get('/lang/' + lang + '.js', function(data){ // dynamically load moment lang file based on browser settings
        var script = document.createElement('script');
        script.innerHTML = data;
        head.append(script);
        moment().lang(lang); // tell moment to use browser lang settings globally
      });
    }

when on the server, moment requires in the file internally. when on the client, we get the lang file and append it to <head> then pass the lang into moment ot use it.

thus when firefox requests zh, there is no zh.js and the GET request fails (node server cannot find zh.js). hope that all makes sense; if you need any more info I will be happy to provide it.

@ichernev
Copy link
Contributor

ichernev commented May 1, 2014

Why don't you simlink zh.js to zh-cn.js on the server end. Otherwise I don't think its politically correct to rename it.

@ichernev ichernev closed this as completed May 1, 2014
@gdibble
Copy link
Contributor Author

gdibble commented May 1, 2014

not every platform has symlink available. my enterprise is hosted in azure.
the issue is to figure out if zh = zh-cn, so re-opened because this is something anyone with FireFox will run into. bottom line: we need a zh.js file. thanks

@ichernev
Copy link
Contributor

ichernev commented May 1, 2014

Cant you manually copy the lang file?
On May 1, 2014 11:18 AM, "Gabriel Dibble" notifications@github.com wrote:

not every platform has symlink available. my enterprise is hosted in
azure.
the issue is to figure out if zh = zh-cn, so re-opened because this is
something anyone with FireFox will run into


Reply to this email directly or view it on GitHubhttps://github.com//issues/1494#issuecomment-41938520
.

@gdibble
Copy link
Contributor Author

gdibble commented May 2, 2014

(: Yes, already done.
Created issue in hopes of helping others with same problem. All we need is someone with the appropriate knowledge to advise on the proper default (cn?) for 'zh.js'

@ghost
Copy link

ghost commented Apr 9, 2015

Why is this closed?
The 'zh' file should be available in the moment-with-locales.js and it should be the fallback for "zh-XX".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants