Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Make an npm module #31

Closed
jamesarosen opened this issue Jan 13, 2013 · 7 comments
Closed

Make an npm module #31

jamesarosen opened this issue Jan 13, 2013 · 7 comments

Comments

@jamesarosen
Copy link
Owner

This depends on https://github.com/jamesarosen/CLDR.js, which isn't an npm module. There's already a cldr project in npm, but it isn't browser-friendly because it requires a CLDR data XML file.

@jamesarosen
Copy link
Owner Author

@papandreou would it be at all possible to make https://github.com/papandreou/node-cldr browser-friendly? If not, I can register my CLDR.js as in npm as "cldr-browser" to avoid the conflict with yours.

@papandreou
Copy link

@jamesarosen: node-cldr is just the code for extracting stuff from CLDR, so it's not meant to be used in a browser. However, it's very useful if you're building a browser-compatible library. I'm building one myself: https://github.com/papandreou/inter -- but I chose to move all the non-opinionated, boring extraction code into a separate library so others could benefit from it.

It would be pretty easy to recreate your CLDR.js with node-cldr as a build-time dependency. It looks like you've hand-transcribed those pluralization rules?

@jamesarosen
Copy link
Owner Author

I sure did! That's actually not a bad idea: build a grunt task to generate a library from node-cldr. I wasn't able to find the pluralization rules in inter itself; perhaps that's a TODO. Let me know if you'd like to collaborate on any of this stuff. I'm all for reducing redundancy if the use cases match up well enough. My CLDR.js is meant to support Ember-I18n.

@papandreou
Copy link

I'd be happy to lend a hand! Something like this could generate the main part of your plurals.js (except for the enum):

var cldr = require('cldr')('/path/to/cldr'),
    localeIdsByPluralRuleFunctionSource = {};

cldr.localeIds.forEach(function (localeId) {
    var pluralRuleFunctionSource = cldr.extractPluralRuleFunction(localeId).toString().replace(/^function anonymous/, "function"); // Fix V8-ism
    (localeIdsByPluralRuleFunctionSource[pluralRuleFunctionSource] = localeIdsByPluralRuleFunctionSource[pluralRuleFunctionSource] || []).push(localeId);
});

Object.keys(localeIdsByPluralRuleFunctionSource).forEach(function (pluralRuleFunctionSource) {
    var localeIds = localeIdsByPluralRuleFunctionSource[pluralRuleFunctionSource];
    console.log("define([" + localeIds.map(function (localeId) {return "'" + localeId + "'";}).join(",") + '], ' + pluralRuleFunctionSource + ');');
});

Output:

define(['fil','ti','am_et','nso','ak','ln_cf','ak_gh','ln_cd','fil_ph','ti_et','hi','mg','hi_in','nso_za','ln_cg','ln','ln_ao','mg_mg','am','ti_er'], function(n) {
if(n>=0&&n<=1)return"one";return"other"
});
define(['en_ag','seh_mz','en_ug','rwk_tz','en_ie','es_gt','pt_st','fur_it','pa_guru_in','nr','en_bm','seh','ml_in','tn_za','sq_mk','it_sm','rof','ee_tg','en_to','os_ge','jgo_cm','el_gr','ta_in','en_pg','es_bo','nn','fur','kl','mgo','fo_fo','ss_sz','wae','en_bs','en_gu','gl_es','xog','es_cr','es_do','sn_zw','en_ky','ur','es_cl','en_us_posix','so_so','en_tz','ca_ad','ky','en_pr','en_ke','en_bb','nl_aw','ky_kg','om_ke','gsw','de_lu','mas_ke','nl_cw','as','en_zm','ksb','en_ws','en_us','en_gy','bn_bd','saq','en_jm','bg_bg','is_is','mas','rm_ch','te','kk','ee_gh','ha_latn_ng','ks','bez','en','es_cu','af','es_ea','en_ls','en_za','bem','en_je','da','en_be','tn_bw','pa','kkj_cm','nyn','sq','ps','tn','es_pe','en_mg','en_as','nr_za','nl_sx','vo','ha_latn','en_zw','mr_in','ta_my','ta','wae_ch','as_in','es_ni','ee','cgg_ug','en_gg','st_ls','ks_arab','ssy_er','pt_mz','brx_in','en_vg','nnh','xh_za','de_ch','ssy','el','haw','nd','os_ru','en_in','de','pt_cv','pt_br','en_vc','nyn_ug','sw_tz','so','pt_pt','bn','en_pk','zu','es_uy','ha_latn_ne','en_tc','kk_cyrl_kz','zu_za','chr_us','ha_latn_gh','nn_no','pa_guru','haw_us','is','gu_in','pt_tl','en_au','pa_arab','ml','tig','es_ve','en_dsrt_us','gu','es_ar','en_mh','en_ph','rwk','ss','es_mx','vun_tz','sv_se','pa_arab_pk','nl_be','en_kn','or','en_hk','en_pw','gsw_ch','bg','en_gd','fo','ks_arab_in','es_419','en_sg','st','ksb_tz','teo_ke','asa_tz','mr','de_at','sv','lg','da_dk','asa','pt_mo','ha','en_sc','os','or_in','en_gh','en_lr','cgg','en_tt','kkj','xh','ca_es','es_pr','sw','sw_ke','es_gq','saq_ke','en_150','en_gm','en_na','en_gi','vun','en_lc','nb','so_dj','xog_ug','nd_zw','af_za','ve_za','en_sz','en_ca','so_ke','te_in','es_co','bn_in','el_cy','ast','ur_in','ne_np','pt_ao','es_pa','de_li','ts_za','en_vu','sv_ax','de_de','sn','de_be','nl_sr','eu_es','teo','rof_tz','ta_sg','es_us','lg_ug','sw_ug','en_bz','rm','eu','gl','en_mt','ur_pk','en_ki','bem_zm','af_na','en_bw','en_mw','ast_es','fi','sv_fi','jgo','eo','en_im','jmc_tz','ne_in','es','en_dsrt','en_ss','en_fm','pt','es_hn','en_sl','en_mp','en_vi','es_ec','it_ch','bez_tz','brx','nnh_cm','en_nz','om_et','fi_fi','nl_nl','es_py','es_ph','om','et_ee','en_cm','nb_no','en_mu','mas_tz','et','es_ic','en_gb','kk_cyrl','it','chr','sq_al','ve','ta_lk','ts','mgo_cm','so_et','teo_ug','ps_af','ss_za','es_es','en_dm','nl','st_za','es_sv','en_fj','ne','en_um','kl_gl','tig_er','ca','jmc','en_ng','it_it','pt_gw','en_sb'], function(n) {
if(n===1)return"one";return"other"
});

... And so on.

I wasn't able to find the pluralization rules in inter itself; perhaps that's a TODO

It's a little weird right now, and the docs are outdated. My plans is to clean it up and AMD-ify it properly, but I need to fix some things in my build system to make it work first.

@jamesarosen jamesarosen mentioned this issue Jan 14, 2013
9 tasks
@jamesarosen
Copy link
Owner Author

@papandreou one of the things we're considering is a npm library that has node-closure as a dependency and writes out I18n-related modules (plurals, number_formats, etc.). Closure Compiler has all that logic built-in -- no need to parse it out of XML files.

@papandreou
Copy link

@jamesarosen That'd be another fine solution, although it would be one step further from the real data source (Closure also gets all that data from CLDR). You'd be reliant on both node-closure and Closure staying alive and releasing new versions of their code in a timely manner.

Sorry I can't promise any time frame with inter. I'm mostly struggling with coming up with a nice API that works well in both node.js and the browser so that things are still split up enough that you only pay for the features that you use. Things like localized time zone lists need to be split up per locale because they're so huge, whereas pluralization rules are compact enough that a single lib can contain the data for all locales. My current approach is to use buildInter --bundle to build one huge library with all the features and locales you need for your project, and then use uglifyjs --define LOCALEID="en_us" etc. to split it into trimmed-down libraries for production that only contain one locale each. Not exactly self-explanatory.

@jamesarosen
Copy link
Owner Author

Great info, thanks :)

We'll try building a smaller library from both closure and node-cldr and see how they go.

@heartsentwined heartsentwined mentioned this issue Apr 14, 2013
swquinn added a commit to swquinn/ember-i18n that referenced this issue Sep 13, 2016
The removal of the ember-i18n initializer had unseen consequences for
applications that were injecting the i18n service into other areas of
the application, as recommended by documentation in the project's wiki
(https://github.com/jamesarosen/ember-i18n/wiki/Doc:-i18n-Service).

As per the discussion in jamesarosenGH-31 this adds a no-op initializer back into
the code base to prevent breaks for applications injecting the i18n
service as per the wiki.
jamesarosen added a commit that referenced this issue Sep 13, 2016
GH-403: Add no-op ember-i18n initializer
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants