Skip to content
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

feat: load remote catalogs with remoteLoader() #1080

Merged
merged 1 commit into from
Jun 8, 2021
Merged

Conversation

semoal
Copy link
Contributor

@semoal semoal commented Jun 8, 2021

This new feature opens a whole world for loading the messages:

Now you could perfectly store your .json, .po, or even .csv files of Lingui in remote environments like an AWS S3, and recover them dynamically.

Basically now you could so something similar to this:

import { i18n } from "@lingui/core"
import { remoteLoader } from "@lingui/loader"

export async function remoteActive(locale: string) {
  const remoteMessages = await fetch(`https://some-api/${locale}/messages`)
  const compiledMessages = remoteLoader(locale, remoteMessages)
  i18n.load(locale, compiledMessages)
  i18n.activate(locale)
}

How does this handle fallbacks?

You can perfectly pass a fallback messages object, it can be a .json file or even a .po file.

import { i18n } from "@lingui/core"
import { remoteLoader } from "@lingui/loader"

import { messages as fallbackMessages } from "./locales/en/messages"

export async function remoteActive(locale: string) {
  const remoteMessages = await fetch(`https://some-api/${locale}/messages`)
  const compiledMessages = remoteLoader(locale, remoteMessages, fallbackMessages)
  i18n.load(locale, compiledMessages)
  i18n.activate(locale)
}

There's pending to write documentation of this, I'll push the documentation along the week since I'm not sure if this will 100% work great

@vercel
Copy link

vercel bot commented Jun 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/lingui-js/js-lingui/HcpZSkoxQjFqNvaAW14p3DqpMLNe
✅ Preview: https://js-lingui-git-feat-remote-loader-lingui-js.vercel.app

@github-actions
Copy link

github-actions bot commented Jun 8, 2021

size-limit report 📦

Path Size
./packages/core/build/cjs/core.production.min.js 2.78 KB (0%)
./packages/detect-locale/build/cjs/detect-locale.production.min.js 798 B (0%)
./packages/react/build/cjs/react.production.min.js 4.85 KB (0%)
./packages/core/build/esm/index.js 2.75 KB (0%)
./packages/core/build/esm/dev.js 7.01 KB (0%)
./packages/detect-locale/build/esm/index.js 852 B (0%)
./packages/react/build/esm/index.js 4.83 KB (0%)

@semoal semoal changed the title feat: remoteLoader introduced feat: load remote catalogs with remoteLoader() Jun 8, 2021
@semoal semoal merged commit e73a4b3 into main Jun 8, 2021
@semoal semoal deleted the feat-remote-loader branch June 8, 2021 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant