-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add twitter-cldr for bidirectional text support #1841
Conversation
@@ -1,6 +1,8 @@ | |||
'use strict'; | |||
|
|||
var resolveTokens = require('../util/token'); | |||
var TwitterCLDR = require('../../node_modules/twitter_cldr/min/en.min.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't rely on node_modules path, you can't just do require('twitter_cldr/min/en.min.js')
In theory, if we write a simple bidi algorithm implementation, we could cut this down to just a few tens of kilobytes. All we need is the codepoint mapping to see if a particular character is RTL or not:
Total 14kb. |
ed975d5
to
5d1d891
Compare
Extracted the bidi logic from twitter-cldr-js in 0ed31d5 and dropped the uncompressed size down to ~25kb. 5d1d891 is supposedly faster, but balloons |
I think the structure rewrite can be easily done in JS (once), not statically. |
@mourner The codepoint mapping is where most of the size of the bidi feature comes from. When I initially wrote the feature I struggled to compress the mapping into a reasonable size. I'm sure more could be done in this regard (prefix tree, perhaps?). |
Alright, finally got a chance to look at this again. Most of the weight appears to come from the
There are a few variations I want to benchmark for performance and size, one with single-entry arrays for the single-codepoint ranges, and another splitting out a big array for each Variant A
Variant B
@camertron I'm not actually sure what a prefix tree is, would love a little more detail if you think it's a worthwhile approach. |
@camertron Would appreciate if you could point me to the source data for https://github.com/twitter/twitter-cldr-js/blob/master/lib/twitter_cldr/js/mustache/implementation/shared/prerender/bidi_classes.json in http://unicode.org/Public/8.0.0/ucd/ |
@mikemorris Here's the code that generates them. |
Have you considered formats other than JSON for storing this data? In particular, the |
I am closing this PR because it has been inactive for a long time. The branch isn't going anywhere so please keep working on this feature and re-open the PR when it is ready! Let me know if you have any questions. |
This looks like it's currently inflating the size of the browserify'd package by over 1MB. I'm not sure how much of this could be avoidable by extracting the bidi logic from https://github.com/twitter/twitter-cldr-js (ugh, CoffeeScript) - right now this just pulls in the entire
en.min.js
localization file withdatetime
logic and such too. I THINK the bidi logic is templated and identical across all locales?BUT, at least preliminarily, It Works™
Before
After
Refs mapbox/DEPRECATED-mapbox-gl#4