wooorm / bcp-47 Goto Github PK
View Code? Open in Web Editor NEWParse and stringify BCP 47 language tags
License: MIT License
Parse and stringify BCP 47 language tags
License: MIT License
I don't know if this is in the scope of this project, but when I got here I expected to get the actual name of the language of a parsed language tag. I realize this library currently just implements the specification itself and doesn't keep a list of all subtags, but maybe we can change that? Sure, the subtag registry is huge but also the only resource to get the actual language names and scopes from. I think with some tricks we can compress that list, especially regarding the redundant
and grandfathered
entries. Also, not all entries are languages, but just regions or scripts, since this is a list of all possible subtags. Some metadata:
Type: language
Description
values, it seems like just caring about the first one of each entry is enoughHere is a short gist from me which converts the registry to a json that could be readable by this library:
https://gist.github.com/nnmrts/7f06da21729a7d495cdee147271847b5
In these referenced line, the import doesn't include the .json
extension, which is creating problems for Webpack. Could this be fixed? I've already tested that just adding the extension fixes the problem. If a PR is welcome, I'd be glad to make it.
Lines 6 to 7 in ff06090
Using the package as: const schema = parse('x-whatevertag', {warning: true})
, results in error:
if (options.warning) options.warning(reason, code, offset)
^
TypeError: options.warning is not a function
at fail (file:///C:/Users/.../node_modules/bcp-47/lib/parse.js:288:34)
at parse (file:///C:/Users/.../node_modules/bcp-47/lib/parse.js:258:18)
at file:///C:/Users/.../src/test.js:3:16```
Probably not scope of your package but I am longing for a function to return me a BCP 47 language tag based by a top level domain (TLD).
Have initially reported the need in petert82/country-query#3 but since it seems inactive, and yours comes - after some research - the most close, I wonder why not ask you about that?
Is there any interest in a PR to include TypeScript definitions in this project? If so, I'd be glad to make a PR for them.
This package does not treat the tag en-a-bbb-a-ccc
as invalid even though the singleton subtag a
appears twice.
According to the BCP 47 specifications: Each singleton subtag MUST appear at most one time in each tag (other than as a private use subtag). That is, singleton subtags MUST NOT be repeated. For example, the tag "en-a-bbb-a-ccc" is invalid because the subtag 'a' appears twice. Note that the tag "en-a-bbb-x-a-ccc" is valid because the second appearance of the singleton 'a' is in a private use sequence.
Is this an issue that needs to be fixed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.