Skip to content

Replace country-regex with i18n-iso-countries #7366

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dimitrov570
Copy link

Resolves the issue discussed in #7026.

This implementation does not use regular expressions as before and does not contain countries that do not exist anymore, compared to the previous solution with country-regex. But on the other hand i18n-iso-countries seems to be updated frequently, so it will contain updated information on country codes.

@gvwilson gvwilson added community community contribution P1 needed for current cycle fix fixes something broken labels Feb 18, 2025
@gvwilson
Copy link
Contributor

thanks @dimitrov570 - I'll see if we can get this into the 3.1 release.

Copy link
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I left a few comments. Could you please merge master and handle the merge conflicts?

@gvwilson there are 6 codes removed from the new package. Would this count as a breaking change? The countries don't exist anymore.

Code Country
ANT Netherlands Antilles
CSK Czechoslovakia
DDR German Democratic Republic
EAZ Zanzibar
YMD South Yemen
YUG Yugoslavia

@@ -0,0 +1 @@
- Replace country-regex with i18n-iso-countries [[#7366](https://github.com/plotly/plotly.js/pull/7366)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Replace country-regex with i18n-iso-countries [[#7366](https://github.com/plotly/plotly.js/pull/7366)]
- Replace country-regex package with i18n-iso-countries [[#7366](https://github.com/plotly/plotly.js/pull/7366)]

@@ -12,8 +11,8 @@ var isPlainObject = require('./is_plain_object');
var nestedProperty = require('./nested_property');
var polygon = require('./polygon');

// make list of all country iso3 ids from at runtime
var countryIds = Object.keys(countryRegex);
const countries = require("i18n-iso-countries");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this require statement above with the others?

@gvwilson
Copy link
Contributor

I don't think the deleted countries counts as a breaking change.

@camdecoster camdecoster self-requested a review July 30, 2025 20:00
@camdecoster
Copy link
Contributor

I clicked the wrong button. Let me know when you make changes and I'll review again.

@dimitrov570
Copy link
Author

I clicked the wrong button. Let me know when you make changes and I'll review again.

Sorry, I was away. Let me know if anything else needs to be done.

@camdecoster
Copy link
Contributor

Welcome back! There's a couple of failing tests due to the library change and country names not being available anymore. I should have it fixed today, then I'll merge it.

@dimitrov570
Copy link
Author

You would fix it or I should fix it? I'm not 100% sure what needs to be done, but I suppose just to remove the countries that are not present anymore from the tests, right?

@camdecoster
Copy link
Contributor

You would fix it or I should fix it? I'm not 100% sure what needs to be done, but I suppose just to remove the countries that are not present anymore from the tests, right?

I took care of it. Once CI passes, I'll get it merged.

@camdecoster
Copy link
Contributor

For future reference, there was an issue where ESBuild was treating the required en.json file as JavaScript instead of JSON. The error I saw was this: Expected ";" but found ":" . This was due to our use of an ESBuild plugin browserifyAdapter, where we passed a custom transform function:

module.exports = function() {
var allChunks = [];
return through(function(chunk, enc, next) {
allChunks.push(chunk);
next();
}, function(done) {
var str = Buffer.concat(allChunks).toString('utf-8');
this.push(
str
.replace(makeStringRegex('description'), '')
.replace(makeJoinedArrayRegex('description'), '')
.replace(makeArrayRegex('requiredOpts'), '')
.replace(makeArrayRegex('otherOpts'), '')
.replace(makeStringRegex('role'), '')
.replace(makeStringRegex('hrName'), '')
);
done();
});
};

I'm not sure why this happened because ESBuild can handle JSON files, but it was necessary to stringify the JSON to get ESBuild to recognize the file as JSON. An alternative that worked was to wrap the text in module.exports = { <JSON text> }, which is what ESBuild ultimately does during the build process.

On another note, the library that this PR replaces uses RegEx patterns to match country names which is pretty flexible (though a bit out of date). The new library looks for an exact match of lowercased strings. As such, some previous country names no longer find a match. For example, a location of Burma no longer returns the country code for Myanmar and a location of Moldova no longer matches because it needs to be "Moldova, Republic of". There are some open PRs to add alternative names (like just "Moldova"), but those haven't been getting approved very quickly. Once they do, we can update the library and make the country lookup a bit better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution fix fixes something broken P1 needed for current cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy