Coder Social home page Coder Social logo

node-i18n-iso-countries's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-i18n-iso-countries's Issues

Impossible to use this module with create-react-app

I'm trying to use this module with create-react-app but I get a compilation error:

Failed to minify the code from this file: 

 	./node_modules/i18n-iso-countries/index.js:46 

Read more here: http://bit.ly/2tRViJ9

Following the link brings to this page: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled.

Any chance the module could be pre-compiled before it's published?

getNames returns empty object in Vue.js

Using this library for a form in a Vue.js application the following getNames function call returns an empty object, however, the rest of the functions seem to work as expected.

var countries  = require('i18n-iso-countries')
var codes      = countries.getNames('en')
var alpha2     = countries.getAlpha2Codes()

console.log(codes)   // Empty {}
console.log(alpha2)) // Works as expected

Getting compile errors with 3.7.2 using tsc

It works fine on 3.7.1 but 3.7.2 gives following compile errors:


node_modules/i18n-iso-countries/index.d.ts(11,16): error TS7010: '(Missing)', which lacks return-type annotation, implicitly has an 'any' return type.
node_modules/i18n-iso-countries/index.d.ts(11,17): error TS1003: Identifier expected.
node_modules/i18n-iso-countries/index.d.ts(11,24): error TS2552: Cannot find name 'lang'. Did you mean 'langs'?
node_modules/i18n-iso-countries/index.d.ts(11,28): error TS1005: ',' expected.
node_modules/i18n-iso-countries/index.d.ts(11,30): error TS2693: 'string' only refers to a type, but is being used as a value here.
node_modules/i18n-iso-countries/index.d.ts(11,37): error TS1005: ';' expected.
node_modules/i18n-iso-countries/index.d.ts(11,43): error TS1109: Expression expected.```

I see weird characters in countries name in German language

Can I know why do I receive weird characters in countries name in German language?

Südafrika
São Tomé und Príncipe
Südsudan
Russische Föderation
Südkorea
Französisch-Guayana
Vereinigtes Königreich Gro�britannien und Nordirland

Have anyone experienced this problem?

de.json not correct sorted

Hey :)

First of all, thanks for this package :) 👍
It would be nice, if kosovo is between "Kongo" and "Nordkorea" in de.json / en.json etc. for correct sort :)

Getting compilation error with version 3.7.0: UglifyJs fails

Hi there,

we are using i18n-iso-countries with webpack. Maybe someone else stumbles upon this and receives the following:

2018-06-26T14:50:41.5178144Z WARNING in ./node_modules/i18n-iso-countries/index.js
2018-06-26T14:50:41.5178337Z 46:18-63 Critical dependency: the request of a dependency is an expression
2018-06-26T14:50:41.5178523Z  @ ./node_modules/i18n-iso-countries/index.js
2018-06-26T14:50:41.5178679Z  @ ./src/i18n/i18nCountries.js
2018-06-26T14:50:41.5178825Z  @ ./src/index.jsx
2018-06-26T14:50:41.5178965Z  @ multi ./src/index.jsx
2018-06-26T14:50:41.5179055Z 
2018-06-26T14:50:41.5179351Z ERROR in bundle.js from UglifyJs
2018-06-26T14:50:41.5179512Z Unexpected token: name (localData) [bundle.js:29002,6]

We had now one day broken builds because of that. The reason was, that in our package.json we allowed also minor version upgrades with "i18n-iso-countries": "^3.6.2". Changing it to "i18n-iso-countries": "~3.6.2" to ensure only patching is done and it stays at version 3.6.x solved it.

I actually even commented out the minification with UglifyJs, but yet the error still persists. I guess it has to do with missing ES6 transpilation or something like that in i18n-iso-countries and thus UglifyJs fails. However, I do not want to include the node_modules folder in my ES6 transpilation process.

import is not a function v 3.7.1

I am using release 3.7.1 and I am trying to use the import function, but I got the error

import is not a function

Checking the index.d.ts looks like the mapping to that function is missing

export type LocalizedCountryNames = { 
  [alpha2Key: string]: string 
};

export type LocaleData = {
  locale: string,
  countries: LocalizedCountryNames
};

export function registerLocale(localeData: LocaleData): void;
export function alpha2ToAlpha3(alpha2: string): string;
export function alpha2ToNumeric(alpha2: string): number;
export function alpha3ToAlpha2(alpha3: string): string;
export function alpha3ToNumeric(alpha3: string): number;
export function numericToAlpha2(numeric: number | string): string;
export function numericToAlpha3(numeric: number | string): string;
/**
 * Returns object map where key is alpha 2 code and value is alpha 3 code
 */
export function getAlpha2Codes(): { [alpha2Key: string]: string };
/**
 * Returns object map where key is alpha 3 code and value is alpha 2 code
 */
export function getAlpha3Codes(): { [alpha3Key: string]: string };
/**
 * Returns object map where key is numeric code and value is alpha 2 code
 */
export function getNumericCodes(): { [numericKey: number]: string };
export function getName(alpha2orAlpha3orNumeric: string | number, lang: string): string;
export function getNames(lang: string): LocalizedCountryNames;
export function toAlpha3(alpha2orNumeric: number | string): string;
export function toAlpha2(alpha3orNumeric: number | string): string;
export function getAlpha2Code(name: string, lang: string): string;
export function getAlpha3Code(name: string, lang: string): string;
export function langs(): string[];
export function isValid(alpha2orAlpha3orNumeric: string | number): boolean;

Sort countries by name

Hi,
is there any easy way to sort the return of getNames by the value of the country name?

Incorrect statement about using it in nodejs, still require registerLocale

Following statement seems invalid:

If you use i18n-iso-countries with Node.js your are done. If you use the package in a browser environment you also have to register the languages you want to use to minimize file size.

I'm using nodejs and it will show undefined for my queries until I add the countries.registerLocale specifically. I use it in angular like this:
import * as countries from 'i18n-iso-countries';
Seems it was already mentioned here: #92

Any idea?

Add alternate / shorter names?

Hi @michaelwittig!

I was using this library and figured I'd let you know why I had to switch to another library for ISO 3166 lookup, in case there is an opportunity for improvement.

So far as I can tell, the actual ISO specification does indeed list the name for the US as "United States of America", and I see the issue #33 where this was changed. The problem is that every other ISO 3166 library I've used (and I've tried a bunch) all return "United States".

This is affecting interoperability for me: for example, when I query the Last.fm geo API, the country parameter expects a country name, not a code (extremely weird decision on their part, I know). But now I can't use this library to do the conversion, because the API expects "United States" and fails for "United States of America".

Are all the other libraries and Last.fm are just using outdated ISO 3166 databases? Or is there a short & long name and each library is only exposing one or the other? If this library's purpose is for printing nice i18n strings that's fine, I just figured I'd let you know about this use case in case you want more ISO 3166 interoperability.

Handle BCP47 Standard

The BCP47 Standard is the one where the locale is represented as follow:

language-region

For example: us-EN, us-UK

This great lib should handle that case. A simple split('-')[0] can do the trick

Optimizing for browsers

This is a really cool library but bundling it for usage in a browser results in a massive bundle (146KB for a bundle containing only this library, post-minification, pre-gzip).

Optimizing it wouldn't be too hard and, even while it would require a tiny bit more work on the developers that use this library I believe it would be definitely worth it.


First optimization that can be done is not loading all locales at once but only those needed by the app. There are a couple ways you can do this:

  1. By first registering the locale the app needs:
const countries = require('i18n-iso-countries');

countries.registerLocale(require('i18n-iso-countries/locales/en.json'));
countries.getNames('en'); // returns the list of names in english

countries.getNames('fr'); // throws "unknown locale, please register it first"
  1. Or the date-fns way, where the locale object is used directly:
const countries = require('i18n-iso-countries');
const en = require('i18n-iso-countries/locales/en.json');

countries.getNames(en); // returns the list of names in english

If you wish to keep the "all locales are pre-loaded" behavior on node, you can specify a different entrypoint for browsers than for node in package.json and have the node entrypoint register all locales then call the browser entrypoint.


Second optimization is getting rid of the pad dependency. The reason behind it is that this library is itself dependant on wcwidth, which itself is dependant on defaults, which itself uses clone.

That's a massive amount of code for something like pad, even more now that String.prototype.pad{Start|End} is standard and really easy to polyfill.

The best way to optimize this would be to simply use String.prototype.pad{Start|End} instead of pad, and add a note in the documentation stating that the environment needs to provide a polyfill for that function if it is not natively available. (core-js can provide these polyfills)


I can submit a PR with all this if you are interested.

Thank you :)

Error: Cannot find module './codes.json'

I just installed i18n-iso-countries
and get thee following error:

W20170129-12:30:52.372(1)? (STDERR) Error: Cannot find module './codes.json'
W20170129-12:30:52.373(1)? (STDERR)     at require (packages/modules-runtime.js:114:19)
W20170129-12:30:52.373(1)? (STDERR)     at meteorInstall.node_modules.i18n-iso-countries.index.js (packages/modules.js:1207:13)
W20170129-12:30:52.373(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:188:9)
W20170129-12:30:52.373(1)? (STDERR)     at Module.require (packages/modules-runtime.js:111:16)
W20170129-12:30:52.373(1)? (STDERR)     at Module.Mp.import (/Users/ap/.meteor/packages/modules/.0.7.7.iu0idl++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20170129-12:30:52.373(1)? (STDERR)     at meteorInstall.imports.api.jotForm.server.worker.js (imports/api/jotForm/server/worker.js:1:1)
W20170129-12:30:52.373(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:188:9)
W20170129-12:30:52.374(1)? (STDERR)     at Module.require (packages/modules-runtime.js:111:16)
W20170129-12:30:52.374(1)? (STDERR)     at Module.Mp.import (/Users/ap/.meteor/packages/modules/.0.7.7.iu0idl++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20170129-12:30:52.374(1)? (STDERR)     at meteorInstall.imports.api.jotForm.server.publications.js (imports/api/jotForm/server/publications.js:1:1)
W20170129-12:30:52.374(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:188:9)
W20170129-12:30:52.374(1)? (STDERR)     at Module.require (packages/modules-runtime.js:111:16)
W20170129-12:30:52.374(1)? (STDERR)     at Module.Mp.import (/Users/ap/.meteor/packages/modules/.0.7.7.iu0idl++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20170129-12:30:52.375(1)? (STDERR)     at meteorInstall.imports.startup.server.register-api.js (imports/startup/server/register-api.js:1:1)
W20170129-12:30:52.375(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:188:9)
W20170129-12:30:52.375(1)? (STDERR)     at Module.require (packages/modules-runtime.js:111:16)
W20170129-12:30:52.375(1)? (STDERR)     at Module.Mp.import (/Users/ap/.meteor/packages/modules/.0.7.7.iu0idl++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20170129-12:30:52.375(1)? (STDERR)     at meteorInstall.imports.startup.server.index.js (imports/startup/server/index.js:1:13)
W20170129-12:30:52.375(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:188:9)
W20170129-12:30:52.375(1)? (STDERR)     at Module.require (packages/modules-runtime.js:111:16)
W20170129-12:30:52.375(1)? (STDERR)     at Module.Mp.import (/Users/ap/.meteor/packages/modules/.0.7.7.iu0idl++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20170129-12:30:52.376(1)? (STDERR)     at meteorInstall.server.main.js (server/main.js:1:1)

Dynamic require incompatible with bundler (browserify, webpack...)

Recently change the way you load the lang file:

langs.forEach(function(lang) {
"use strict";
data[lang] = require("./langs/" + lang + ".json");
});

Now you use a loop on all the defined code. Theses dynamics require call cannot be interpreted by code bundler (browserify or webpack). It's break the library: the ./langs/*.json are not bundled with the application so loading of the lib fail.

Could you rollback to a more predictive loading (like before)? I know this make the maintenance harder for you but it's the only way to keep the compatibilities with these tools.

South Korea / North Korea

Can you please handle the non-specific case of when using South Korea vs North Korea, instead of having to use the much more non-common standard of "Korea, Peoples Republic Of".

[PULL] Add a better way to register locales

Hello,

i noticed that my code using your package was returning an empty Dict:

require('i18n-iso-countries').getNames('de') // {}

And so i was wondering what changed, it may be that i updated your package and something broke,
so looked into your code and saw that registeredLocales is by default empty and you have to "import" languages by require.
Would you be interested for me to create a pull request which adds a method like following:

const c = require('i18n-iso-countries').import('de') // or 'en ' or 'fr'
// instead of
const c = require('i18n-iso-countries')
c.registerLocale(require('i18n-iso-countries/langs/de.json'))

... that would be much better to use than having to require a json by path.

Otherwise i really appreciate your work here 👍

Possibility to load only specified languages?

This module looks awesome and I would like to replace our self curated languages lists with it.

As I would like to use it in our web apps, my question: Is it possible to load only specified languages instead of the entire list? We would currently only require two languages and I would like to save transfer bandwidth.

wish: document which ISO 3166-1 variant is supported

Thanks for this module.

The documentation could be improved by documenting that this module deals with 2 letter "ISO 3166-1 alpha 2" country codes.

This distinguishes them from "ISO 3166-1 alpha 3" codes which have 3 characters:

https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3

(In my case, I have a 3 letter code that I want to convert to a 2 letter code. I'm not sure if that's something that would be interest to include in the scope of this module or not).

Issue loading with Webpack 3.5.5

This might be a config issue on my side, but thought I'd mention it.

webpack:///./node_modules/i18n-iso-countries/index.js?:43
codes.forEach(function(codeInformation) {
      ^

TypeError: codes.forEach is not a function
    at eval (webpack:///./node_modules/i18n-iso-countries/index.js?:43:7)
    at Object.<anonymous> ([stdin]:9414:1)
    at __webpack_require__ ([stdin]:20:30)
    at eval (webpack:///./src/components/forms/ProfileBillingForm/ProfileBillingForm.jsx?:12:77)
    at Object.<anonymous> ([stdin]:4459:1)
    at __webpack_require__ ([stdin]:20:30)
    at eval (webpack:///./src/components/forms/ProfileBillingForm/index.js?:1:82)
    at Object.<anonymous> ([stdin]:9101:1)
    at __webpack_require__ ([stdin]:20:30)
    at eval (webpack:///./src/components/ProfileBilling/ProfileBilling.jsx?:6:84)


Any ideas how to resolve?

Wrong documentation

var countries = require("i18n-iso-countries");
console.log(countries.getNames("en"));

This is not working. It is returning empty object. You need to configure a locale in order for it to work:

var countries = require("i18n-iso-countries");
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.getNames("en"));

Documentation is wrong.

Language Codes

So I need something very similar to this library, but instead of ISO country codes to countries, I need to map ISO language codes to languages. I love the approach this library takes and I was wondering if...

a. You'd be open to a fork (renamed node-i18n-iso-languages).
b. Anyone would be interested in helping on the new package.

I'm happy to take the lead on it, but I figure there might be various native speakers who contributed here that could help me bootstrap the different lang.json files containing locale-specific language names.

I did find some similar projects for languages, but none as robust as this one...

Or, if someone does know of a robust alternative for languages instead of countries, please share.

Getting compiling warning with v3.7.0

Getting this warning since updated to 3.7.0:

Compiled with warnings.

./node_modules/i18n-iso-countries/index.js
46:18-63 Critical dependency: the request of a dependency is an expression

Is there a way to ignore this warning? Thanks!

Add method `isValid`

I need a method to validate a country code. Currently I'm doing toAlpha3(code) !== undefined. But I'd prefer that logic to be encapsulated into the node-i18n-iso-countries package and to call a simple isValid method.

List of country codes

Add function to fetch list of country codes, something similar to

const countryCodes = require('i18n-iso-countries/codes.json').map(info => info[0])

Alphabetical country list

Hi,

It would be nice to have a function to return an array of country names, with their codes, sorted alphabetically by the locale. Useful for drop down lists.

Handle withdrawn ISO-3166 codes

On the referenced Wikipedia page there is a section with withdrawn codes: https://en.wikipedia.org/wiki/ISO_3166-1_numeric#Withdrawn_codes

I found myself getting data from a customer containing some of these withdrawn codes.
Is there any reason not to include these as well? There should be no conflicts between current and withdrawn codes so I don't see any harm in returning data for a code that is officially no longer part of the standard but may still be in use?
Would you accept a PR adding these codes?

If needed, it could of course be made configurable, such as:

const countries = require('i18n-iso-countries')({includeWithdrawn: true});
const alpha2 = countries.numericToAlpha2('230');

or

const countries = require('i18n-iso-countries');
countries.configure({includeWithdrawn: true});
const alpha2 = countries.numericToAlpha2('230');

or, in each individual call:

const countries = require('i18n-iso-countries');
const alpha2 = countries.numericToAlpha2('230', {includeWithdrawn: true});

Uses includes for Angular 2/4?

Hi,

My question is can I use this library on angular project?

I have this error on compilation:
You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:6) on i18n-iso-countries/langs/ar.json Unexpected token (2:6)

Thanks

3.7.0: Warning with webpack

WARNING in ./node_modules/i18n-iso-countries/index.js 46:18-63
Critical dependency: the request of a dependency is an expression

Belarus in Russian is incorrect

The correct Russian translation for Belarus is Беларусь and not Белоруссия .
could this be fixed?
Thank you

Missing countries data

Hi,
I can see that countries data are missing

  • Martinique
  • Netherlands Antilles
  • South Korea
    Best

Greek language code gr vs. el

Hello,

since a few days greek is supported as language, using the getName(country, language) function. But I wonder why the language code was renamed from el to gr in this commit:

a331231

I thought that ISO_3166-1 define countries and e.g. iso 639 define language codes? Since you can also pass "ar" as language, which in this context is the language code from "arabic" and not the country "argentina". So it is only consequent to use "el" instead of "gr" as language code, when you mean greek (the language).

I think I am also confused, because the documentation of the getName function does not clearly state, what iso-definition the language-parameter should conform to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.