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

Add RTL to with-next-translate example #22808

Merged
merged 5 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/with-next-translate/i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"locales": ["en", "ca"],
"locales": ["en", "ca", "ar", "he"],
"defaultLocale": "en",
"pages": {
"*": ["common"],
Expand Down
5 changes: 5 additions & 0 deletions examples/with-next-translate/locales/ar/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "مثال with-next-translate",
"powered": "Powered by",
"alt": "Vercel logo"
}
14 changes: 14 additions & 0 deletions examples/with-next-translate/locales/ar/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"arabic": "العربية",
"catalan": "الكاتالونية",
"change-arabic": "تغيير اللغة إلى العربية ",
"change-catalan": "تغيير اللغة إلى الكتالانية",
"change-english": "تغيير اللغة إلى اللغة الإنجليزية ",
"change-hebrew": "تغيير اللغة إلى العبرية",
"description": "ابدأ بالتعديل",
"english": "الإنجليزية",
"hebrew": "العبرية",
"next-docs": "اعثر على معلومات متعمقة حول ميزات Next.js وواجهة برمجة التطبيقات. ",
"plugin-docs": "اقرأ المزيد عن استخدام الترجمة التالية. ",
"title": "<0>مرحبا بك في <1></1></0>"
}
4 changes: 4 additions & 0 deletions examples/with-next-translate/locales/ca/home.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"arabic": "Àrab",
"catalan": "Català",
"change-arabic": "Canvia a la versió en àrab",
"change-catalan": "Canvia a la versió en català",
"change-english": "Canvia a la versió en anglès",
"change-hebrew": "Canvieu a la versió hebrea",
"description": "Comença editant",
"english": "Anglès",
"hebrew": "Hebreu",
"next-docs": "Troba informació detallada sobre l'API de Next.js.",
"plugin-docs": "Llegeix més sobre com fer servir next-translate.",
"title": "<0>Benvingut a <1></1></0>"
Expand Down
4 changes: 4 additions & 0 deletions examples/with-next-translate/locales/en/home.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"arabic": "Arabic",
"catalan": "Catalan",
"change-arabic": "Change language to Arabic",
"change-catalan": "Change language to Catalan",
"change-english": "Change language to English",
"change-hebrew": "Change language to Hebrew",
"description": "Get started by editing",
"english": "English",
"hebrew": "Hebrew",
"next-docs": "Find in-depth information about Next.js features and API.",
"plugin-docs": "Read more about next-translation usage.",
"title": "<0>Welcome to <1></1></0>"
Expand Down
5 changes: 5 additions & 0 deletions examples/with-next-translate/locales/he/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "דוגמא with-next-translate",
"powered": "Powered by",
"alt": "Vercel logo"
}
14 changes: 14 additions & 0 deletions examples/with-next-translate/locales/he/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"arabic": "עֲרָבִית",
"catalan": "קטלאנית",
"change-arabic": "שנה שפה לערבית",
"change-catalan": "שנה שפה לקטלונית",
"change-english": "שנה שפה לאנגלית",
"change-hebrew": "שנה את השפה לעברית",
"description": "התחל על ידי עריכה",
"english": "אנגלית",
"hebrew": "עִברִית",
"next-docs": "מצא מידע מעמיק על התכונות וה- API של Next.js.",
"plugin-docs": "קרא עוד על השימוש בתרגום הבא.",
"title": "<0>ברוך הבא ל <1></1></0>"
}
31 changes: 26 additions & 5 deletions examples/with-next-translate/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import useTranslation from 'next-translate/useTranslation'
import Layout from '../components/Layout'

export default function Home() {
const { t } = useTranslation()
const { t, lang } = useTranslation()
const isRTL = lang === 'ar' || lang === 'he'
const arrow = isRTL ? String.fromCharCode(8592) : String.fromCharCode(8594)

return (
<Layout>
<main>
<main dir={isRTL ? 'rtl' : 'ltr'}>
<Trans
i18nKey="home:title"
components={[
Expand Down Expand Up @@ -36,16 +38,30 @@ export default function Home() {
</div>
</Link>

<Link href="/" locale="ar">
<div className="card">
<h3>{t('home:arabic')}</h3>
<p>{t('home:change-arabic')}</p>
</div>
</Link>

<Link href="/" locale="he">
<div className="card">
<h3>{t('home:hebrew')}</h3>
<p>{t('home:change-hebrew')}</p>
</div>
</Link>

<a href="https://nextjs.org/docs" className="card">
<h3>Next.js &rarr;</h3>
<h3>Next.{`js ${arrow}`}</h3>
<p>{t('home:next-docs')}</p>
</a>

<a
href="https://github.com/vinissimus/next-translate"
className="card"
>
<h3>Learn &rarr;</h3>
<h3>{`Learn ${arrow}`}</h3>
<p>{t('home:plugin-docs')}</p>
</a>
</div>
Expand Down Expand Up @@ -119,8 +135,9 @@ export default function Home() {
}

.card h3 {
margin: 0 0 1rem 0;
display: flex;
font-size: 1.5rem;
margin: 0 0 1rem 0;
}

.card p {
Expand All @@ -129,6 +146,10 @@ export default function Home() {
line-height: 1.5;
}

[dir='rtl'] p {
text-align: right;
}

@media (max-width: 600px) {
.grid {
width: 100%;
Expand Down