-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
533c69f
commit 15c0c16
Showing
10 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>vocab simple-vite plugin test</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/client.tsx"></script> | ||
</body> | ||
</html> |
This file contains 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,23 @@ | ||
{ | ||
"name": "@vocab-fixtures/simple-vite", | ||
"version": "1.0.0", | ||
"author": "SEEK", | ||
"private": true, | ||
"scripts": { | ||
"compile": "vocab compile", | ||
"start": "vocab compile --watch & vite", | ||
"build": "vocab compile && vite build" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.12.0", | ||
"@types/react": "^18.0.9", | ||
"@types/react-dom": "^18.0.4", | ||
"@vocab/cli": "workspace:*", | ||
"@vocab/core": "workspace:*", | ||
"@vocab/pseudo-localize": "workspace:*", | ||
"@vocab/react": "workspace:*", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0", | ||
"vite": "^5.4.8" | ||
} | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"hello": { | ||
"message": "Bonjour" | ||
}, | ||
"world": { | ||
"message": "monde" | ||
} | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"hello": { | ||
"message": "Hello" | ||
}, | ||
"world": { | ||
"message": "world" | ||
} | ||
} |
This file contains 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,83 @@ | ||
import { VocabProvider, useTranslations } from '@vocab/react'; | ||
import type { TranslationKeys } from '@vocab/core'; | ||
import React, { type ReactNode, useState } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import commonTranslations from './.vocab'; | ||
import clientTranslations from './client.vocab'; | ||
|
||
type CommonTranslationKeys = TranslationKeys<typeof commonTranslations>; | ||
|
||
const useCommonTranslation = (key: CommonTranslationKeys) => { | ||
const { t } = useTranslations(commonTranslations); | ||
|
||
return t(key); | ||
}; | ||
|
||
function Content() { | ||
const common = useTranslations(commonTranslations); | ||
const client = useTranslations(clientTranslations); | ||
const message = `${common.t('hello')} ${useCommonTranslation('world')}`; | ||
const specialCharacterResult = client.t( | ||
'specialCharacters - \'‘’“”"!@#$%^&*()_+\\/`~\\\\', | ||
); | ||
const vocabPublishNode = client.t('vocabPublishDate', { | ||
publishDate: 1605847714000, | ||
strong: (children: ReactNode) => <strong>{children}</strong>, | ||
}); | ||
|
||
return ( | ||
<> | ||
<div id="message">{message}</div> | ||
<div id="publish-date">{vocabPublishNode}</div> | ||
<div id="special-characters"> | ||
Special Characters: {specialCharacterResult} | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
function App({ children }: { children: ReactNode }) { | ||
const [lang, setLang] = useState('en'); | ||
const [locale, setLocale] = useState('en-AU'); | ||
|
||
const theLocale = lang === 'en' ? locale : undefined; | ||
|
||
return ( | ||
<VocabProvider language={lang} locale={theLocale}> | ||
{children} | ||
<label htmlFor="languages">Language:</label> | ||
<select | ||
name="languages" | ||
id="language-select" | ||
onChange={(event) => { | ||
setLang(event.currentTarget.value); | ||
}} | ||
> | ||
<option value="en">en</option> | ||
<option value="fr">fr</option> | ||
<option value="pseudo">pseudo</option> | ||
</select> | ||
{lang === 'en' ? ( | ||
<button | ||
id="toggle-locale" | ||
onClick={() => | ||
setLocale((curr) => (curr === 'en-AU' ? 'en-US' : 'en-AU')) | ||
} | ||
> | ||
Toggle locale: {locale} | ||
</button> | ||
) : null} | ||
</VocabProvider> | ||
); | ||
} | ||
|
||
const node = document.createElement('div'); | ||
|
||
document.body.appendChild(node); | ||
|
||
createRoot(node).render( | ||
<App> | ||
<Content /> | ||
</App>, | ||
); |
This file contains 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,8 @@ | ||
{ | ||
"specialCharacters - '‘’“”\"!@#$%^&*()_+\\/`~\\\\": { | ||
"message": "‘’“”'\"!@#$%^&*()_+\\/`~\\\\" | ||
}, | ||
"vocabPublishDate": { | ||
"message": "Vocab a été publié le {publishDate, date, medium}" | ||
} | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"specialCharacters - '‘’“”\"!@#$%^&*()_+\\/`~\\\\": { | ||
"message": "‘’“”'\"!@#$%^&*()_+\\/`~\\\\" | ||
}, | ||
"vocabPublishDate": { | ||
"message": "<strong>Vocab</strong> was published on {publishDate, date, small}" | ||
} | ||
} |
This file contains 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,6 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
plugins: [], | ||
build: {}, | ||
}); |
This file contains 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,13 @@ | ||
const { generator } = require('@vocab/pseudo-localize'); | ||
|
||
module.exports = { | ||
devLanguage: 'en', | ||
languages: [{ name: 'en' }, { name: 'fr' }], | ||
generatedLanguages: [ | ||
{ | ||
name: 'pseudo', | ||
extends: 'en', | ||
generator, | ||
}, | ||
], | ||
}; |
Oops, something went wrong.