NUKnightLab / NUKnightLab/TimelineJS3
Allow to use dynamically created translations
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.2k
- Forks
- 645
- PR merge metrics
- No merged PRs in 30d
Description
Currently, TimelineJS expects the language property to either
- be a string such as
enindicating that some premade json file from a common path (defaulting tohttps://cdn.knightlab.com/libs/timeline3/latest/js/locale) should be used, or - be a URL string ending with
.jsonindicating that some particular premade json file should be used.
It is not possible, however, to use dynamically created language overrides, which would commonly be passed as a JSON object following the same structure as the translation JSON files.
A simple change to https://github.com/NUKnightLab/TimelineJS3/blob/master/src/js/language/Language.js#L242-L251 would allow this. If, for instance, the initial check at https://github.com/NUKnightLab/TimelineJS3/blob/master/src/js/language/Language.js#L243 was turned into
if (
/\.json$/.test(code) ||
/^blob:/.test(code) // dynamically created file (Data URL)
) {
then in particular 3rd party solutions that use TimelineJS as module could simply construct their own translation JSON object dynamically (let us call it foo) and pass it to TimelineJS as a Data URL, e.g. using
URL.createObjectURL(new Blob([JSON.stringify(foo)])) // in proper `try/catch`-clause, sure
If that's something that feels worth adding to TimelineJS (implementation can vary, of course), please let me know.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/js/language/Language.js around lines 242-251, where the language value is checked before loading a translation resource. Verify how a blob: URL is handled alongside existing JSON URLs, while preserving language-code behavior. Done means dynamically created translation JSON can be passed through a Data URL and used by TimelineJS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, internationalization
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100