Update "lazy" loading API
See original GitHub issueIs your feature request related to a problem? Please describe.
I’m using a translation platform Phrase (something like POEditor). They provide “lots of” methods to receive translation files. But none of these methods seems to fit well with vue-i18n
or i18n-module
. Currently my favorite is vue-cli-plugin-i18n
. You just yarn download-translations
into a single folder before generating a project.
tl;dr:
- I don’t have a list of locales (because I receive it from API).
- I don’t have the files (because I receive them from API) (and it would be nice to cache them, because translators keep translating them).
Describe the solution you’d like
options.lazy
(or some other new method like translations
) should accept a string or async function:
const options = {
// /locales contain `locale.(json|js)` translation files
translations: `/locales`,
// API (request handled by module)
translations: locale => `https://translations.server/api/client_id/project_id/${locale}`,
// custom request handling (some people might need custom headers)
translations: async (locale) => axios(`https://translations.server/api/client_id/project_id/${locale}`).data
}
options.locales
should be an optional list of locale Strings or async function:
const options = {
locales: ['en', 'fr', 'es'],
// API
locales: async () => axios(`https://translations.server/api/client_id/project_id/locales-list`).data,
// maybe we can infer locales from `translations` folder? Just like vue-cli plugin?
locales: undefined
}
We might also need some mechanism to cache/invalidate locale list.
Describe alternatives you’ve considered
- Node scripts
- i18next
- Using vue-i18n with plugin that I wrote 2 year ago for custom project
- CI/CD with ENV tricks
Issue Analytics
- State:
- Created 3 years ago
- Comments:14
Top Results From Across the Web
Lazy loading - Web performance | MDN
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the ......
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
In this step, you'll use the useEffect Hook to load asynchronous data into a sample application. You'll use the Hook to prevent unnecessary...
Read more >Fix Lazy-Loaded Website Content | Google Search Central
Lazy loading is a common website performance and UX best practice. Learn how to test and fix lazy loaded content with SEO best...
Read more >Lazy loading using the Intersection Observer API
Lazy loading is a technique that allows us to delay loading nonessential content in our application until after the initial page load.
Read more >Lazy-Loading Update – Make WordPress Core
Since lazy-loading images via the native loading attribute was proposed for addition to WordPress core, there have been quite a few updates.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We could generate just one extra route with the dynamic locale prefix and leave the existing, unprefixed untouched. So there would be just one extra route per route for all locales, rather than one extra route for each locale.
Handling those dynamically sounds too crazy to me so I guess those could only be added at build time.
I’m not sure. It was done like that when I’ve inherited this module. I suppose doing a dynamic locale would pose some challenges. At least locale validation would have to be done on the code level rather than relying on VueRouter validating it now. But it would have the benefit of generating fewer routes which would be good for performance.