question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update "lazy" loading API

See original GitHub issue

Is 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:

  1. I don’t have a list of locales (because I receive it from API).
  2. 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:open
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
rchlcommented, Aug 17, 2020

i.e. no-prefix route.

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.

It also brings me to another tricky question. Which is translated routes.

Handling those dynamically sounds too crazy to me so I guess those could only be added at build time.

1reaction
rchlcommented, Aug 17, 2020

Thank you for reminding me! I totally forgot about “route generation”. I wanted to ask: Why are you generating routes for locales instead of generating dynamic route “_locale”?

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found