-
-
Notifications
You must be signed in to change notification settings - Fork 105
add i18n add-on (paraglide js) #252
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
Open
samuelstroschein
wants to merge
1
commit into
TanStack:main
Choose a base branch
from
samuelstroschein:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Paraglide i18n | ||
|
|
||
| This add-on wires up ParaglideJS for localized routing and message formatting. | ||
|
|
||
| - Messages live in `project.inlang/messages`. | ||
| - URLs are localized through the Paraglide Vite plugin and router `rewrite` hooks. | ||
| - Run the dev server or build to regenerate the `src/paraglide` outputs. |
9 changes: 9 additions & 0 deletions
9
frameworks/react-cra/add-ons/paraglide/assets/messages/de.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "$schema": "https://inlang.com/schema/inlang-message-format", | ||
| "home_page": "Startseite", | ||
| "about_page": "Über uns", | ||
| "example_message": "Willkommen in deiner i18n-App.", | ||
| "language_label": "Sprache", | ||
| "current_locale": "Aktuelle Sprache: {locale}", | ||
| "learn_router": "Paraglide JS lernen" | ||
| } |
9 changes: 9 additions & 0 deletions
9
frameworks/react-cra/add-ons/paraglide/assets/messages/en.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "$schema": "https://inlang.com/schema/inlang-message-format", | ||
| "home_page": "Home page", | ||
| "about_page": "About page", | ||
| "example_message": "Welcome to your i18n app.", | ||
| "language_label": "Language", | ||
| "current_locale": "Current locale: {locale}", | ||
| "learn_router": "Learn Paraglide JS" | ||
| } |
1 change: 1 addition & 0 deletions
1
frameworks/react-cra/add-ons/paraglide/assets/project.inlang/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cache |
12 changes: 12 additions & 0 deletions
12
frameworks/react-cra/add-ons/paraglide/assets/project.inlang/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "https://inlang.com/schema/project-settings", | ||
| "baseLocale": "en", | ||
| "locales": ["en", "de"], | ||
| "modules": [ | ||
| "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js", | ||
| "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js" | ||
| ], | ||
| "plugin.inlang.messageFormat": { | ||
| "pathPattern": "./messages/{locale}.json" | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
frameworks/react-cra/add-ons/paraglide/assets/src/components/LocaleSwitcher.tsx.ejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Locale switcher refs: | ||
| // - Paraglide docs: https://inlang.com/m/gerre34r/library-inlang-paraglideJs | ||
| // - Router example: https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#switching-locale | ||
| import { getLocale, locales, setLocale } from '@/paraglide/runtime' | ||
| import { m } from '@/paraglide/messages' | ||
|
|
||
| export default function ParaglideLocaleSwitcher() { | ||
| const currentLocale = getLocale() | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| gap: '0.5rem', | ||
| alignItems: 'center', | ||
| color: 'inherit', | ||
| }} | ||
| aria-label={m.language_label()} | ||
| > | ||
| <span style={{ opacity: 0.85 }}>{m.current_locale({ locale: currentLocale })}</span> | ||
| <div style={{ display: 'flex', gap: '0.25rem' }}> | ||
| {locales.map((locale) => ( | ||
| <button | ||
| key={locale} | ||
| onClick={() => setLocale(locale)} | ||
| aria-pressed={locale === currentLocale} | ||
| style={{ | ||
| cursor: 'pointer', | ||
| padding: '0.35rem 0.75rem', | ||
| borderRadius: '999px', | ||
| border: '1px solid #d1d5db', | ||
| background: locale === currentLocale ? '#0f172a' : 'transparent', | ||
| color: locale === currentLocale ? '#f8fafc' : 'inherit', | ||
| fontWeight: locale === currentLocale ? 700 : 500, | ||
| letterSpacing: '0.01em', | ||
| }} | ||
| > | ||
| {locale.toUpperCase()} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
34 changes: 34 additions & 0 deletions
34
frameworks/react-cra/add-ons/paraglide/assets/src/routes/demo.i18n.tsx.ejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { createFileRoute } from "@tanstack/react-router"; | ||
| import logo from "../logo.svg"; | ||
| import { m } from "@/paraglide/messages"; | ||
| import LocaleSwitcher from "../components/LocaleSwitcher"; | ||
|
|
||
| export const Route = createFileRoute("/demo/i18n")({ | ||
| component: App, | ||
| }); | ||
|
|
||
| function App() { | ||
| return ( | ||
| <div className="text-center"> | ||
| <header className="min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)] gap-4"> | ||
| <img | ||
| src={logo} | ||
| className="h-[40vmin] pointer-events-none animate-[spin_20s_linear_infinite]" | ||
| alt="logo" | ||
| /> | ||
| <p>{m.example_message({ username: "TanStack Router" })}</p> | ||
| <a | ||
| className="text-[#61dafb] hover:underline" | ||
| href="https://inlang.com/m/gerre34r/library-inlang-paraglideJs" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {m.learn_router()} | ||
| </a> | ||
| <div className="mt-3"> | ||
| <LocaleSwitcher /> | ||
| </div> | ||
| </header> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "Paraglide (i18n)", | ||
| "description": "i18n with localized routing", | ||
| "phase": "add-on", | ||
| "modes": ["file-router"], | ||
| "type": "add-on", | ||
| "priority": 30, | ||
| "link": "https://github.com/paraglidejs/paraglide-js", | ||
| "routes": [ | ||
| { | ||
| "icon": "Languages", | ||
| "url": "/demo/i18n", | ||
| "name": "I18n example", | ||
| "path": "src/routes/demo.i18n.tsx", | ||
| "jsName": "I18nDemo" | ||
| } | ||
| ], | ||
| "integrations": [ | ||
| { | ||
| "type": "header-user", | ||
| "path": "src/components/LocaleSwitcher.tsx", | ||
| "jsName": "ParaglideLocaleSwitcher" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "devDependencies": { | ||
| "@inlang/paraglide-js": "^2.6.0" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <% if (!addOnEnabled.paraglide) { ignoreFile() } %>import { paraglideMiddleware } from './paraglide/server' | ||
| import handler from '@tanstack/react-start/server-entry' | ||
|
|
||
| // Server-side URL localization/redirects for Paraglide | ||
| export default { | ||
| fetch(req: Request): Promise<Response> { | ||
| return paraglideMiddleware(req, ({ request }) => handler.fetch(request)) | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // This file is auto-generated. Do not edit manually. | ||
| // Generated from add-ons, examples, hosts, project, and toolchains directories | ||
| export const contentChecksum = 'b722b3f8235cbf4618c508da1b499a8a6a583d8107eebeb9e2ffe19716ddc7e9' | ||
| export const contentChecksum = '59725486fa40de3b9dbd9b080b1f844dfd17bfdfd5fd79df23f296586ab8ee47' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow JS is needed to make TS treat JSDoc as types. (Paraglide JS compiles to JS with JSDoc)