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(lang): add i18n feature #421

Merged
merged 3 commits into from
Dec 20, 2023
Merged

feat(lang): add i18n feature #421

merged 3 commits into from
Dec 20, 2023

Conversation

kiaking
Copy link
Member

@kiaking kiaking commented Dec 20, 2023

Here we go. I've used Trans inspired by Laravel 👀 Now, we have everything in Sefirot, so I don't think we need to create Lang related things in App except for switching locale and stuff.

This PR only contains localization for required rule, but it shouldn't have breaking change, and localization support can be added incrementally.

// In App.vue
import { provideLang } from 'sefirot/composables/Lang'

const lang = getAppLang()

provideLang(lang)
// Validation rule definition.
import { createRule } from '../Rule'
import { required as baseRequired } from '../validators'

export const message = {
  en: 'The field is required.',
  ja: 'この項目は必須です。'
}

export function required(msg?: string) {
  return createRule({
    message: ({ lang }) => msg ?? message[lang],
    validation: (value) => baseRequired(value)
  })
}

@kiaking kiaking added the enhancement New feature or request label Dec 20, 2023
@kiaking kiaking requested a review from brc-dd December 20, 2023 07:31
@kiaking kiaking self-assigned this Dec 20, 2023
Copy link

netlify bot commented Dec 20, 2023

Deploy Preview for sefirot-story ready!

Name Link
🔨 Latest commit 9930648
🔍 Latest deploy log https://app.netlify.com/sites/sefirot-story/deploys/6582a3d861c2f400086e578b
😎 Deploy Preview https://deploy-preview-421--sefirot-story.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 20, 2023

Deploy Preview for sefirot-docs ready!

Name Link
🔨 Latest commit 9930648
🔍 Latest deploy log https://app.netlify.com/sites/sefirot-docs/deploys/6582a3d88d624200087b8a10
😎 Deploy Preview https://deploy-preview-421--sefirot-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

lib/composables/Lang.ts Outdated Show resolved Hide resolved
@kiaking kiaking merged commit f006fe5 into main Dec 20, 2023
9 checks passed
@kiaking kiaking deleted the 359-lang branch December 20, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add I18N feature
2 participants