The platform supports multiple languages (Turkish and Arabic) with a simple translation system and language switcher.
Supported Languages
Currently supported languages:
- Turkish (Türkçe) 🇹🇷 - Default language
- Arabic (العربية) 🇸🇦
The default language is Turkish. Language preference is saved in localStorage.
Language Configuration
Languages are configured in src/config/language.js:
export const LANGUAGES = {
tr: {
code: 'tr',
name: 'Türkçe',
flag: '🇹🇷',
translations: {
// Product page
seeOptions: "Seçenekleri Görün",
addToCart: "Sepete Ekle",
productDescription: "Ürün seçeneklerini inceleyin ve sipariş verin.",
clickToOrder: "Ürüne tıklayarak WhatsApp ile sipariş verebilirsiniz",
// Order button
orderButton: "Sipariş Ver",
orderUnavailable: "Servis Saatleri Dışındadır",
// Minimum order
minimumOrder: "Minimum sepet tutarı {minimumAmount} TL'dir",
currentCart: "Şu anki sepet: {amount} TL",
// Welcome message
welcomeMessage: "Lütfen ilk siparişinizde adresinizi eklemeyi unutmayın, Teşekkürler.",
understood: "Anladım",
// Scroll indicator
scrollDown: "Kaydır"
}
},
ar: {
code: 'ar',
name: 'العربية',
flag: '🇸🇦',
translations: {
// Product page
seeOptions: "انظر الخيارات",
addToCart: "أضف إلى السلة",
productDescription: "تعرف على خيارات المنتج واطلبه.",
clickToOrder: "يمكنكم الطلب عبر الواتساب بالضغط على المنتج.",
// Order button
orderButton: "اطلب",
orderUnavailable: "خارج ساعات الخدمة",
// Minimum order
minimumOrder: "الحد الأدنى للسلة {minimumAmount} ليرة تركية",
currentCart: "السلة الحالية: {amount} ليرة تركية",
// Welcome message
welcomeMessage: "يرجى عدم نسيان إضافة عنوانكم في طلبكم الأول، شكراً.",
understood: "فهمت",
// Scroll indicator
scrollDown: "تمرر"
}
}
};
export const DEFAULT_LANGUAGE = 'tr';
Translation System
Get Translation
Use the t() function to get translations:
export const t = (key, params = {}) => {
const lang = getCurrentLanguage();
const translation = LANGUAGES[lang]?.translations[key] ||
LANGUAGES[DEFAULT_LANGUAGE]?.translations[key] ||
key;
// Replace parameters
let result = translation;
Object.keys(params).forEach(param => {
result = result.replace(`{${param}}`, params[param]);
});
return result;
};
Usage Examples:
import { t } from '../config/language';
const buttonText = t('addToCart');
// Turkish: "Sepete Ekle"
// Arabic: "أضف إلى السلة"
Language Management
Current Language State
let currentLanguage = DEFAULT_LANGUAGE;
export const getCurrentLanguage = () => {
// Check localStorage on first load
if (typeof window !== 'undefined') {
const saved = localStorage.getItem('suapp-language');
if (saved && LANGUAGES[saved]) {
currentLanguage = saved;
}
}
return currentLanguage;
};
Toggle Language
Switch between Turkish and Arabic:
export const toggleLanguage = () => {
currentLanguage = currentLanguage === 'tr' ? 'ar' : 'tr';
// Save to localStorage
if (typeof window !== 'undefined') {
localStorage.setItem('suapp-language', currentLanguage);
}
return currentLanguage;
};
Get Language Info
export const getCurrentLanguageInfo = () => {
const lang = getCurrentLanguage();
return LANGUAGES[lang];
};
Returns:
{
code: 'tr',
name: 'Türkçe',
flag: '🇹🇷',
translations: { ... }
}
Language Switcher Component
Create a language switcher:
import { useState, useEffect } from 'react';
import { toggleLanguage, getCurrentLanguageInfo } from '../config/language';
function LanguageSwitcher() {
const [langInfo, setLangInfo] = useState(getCurrentLanguageInfo());
const handleToggle = () => {
const newLang = toggleLanguage();
setLangInfo(getCurrentLanguageInfo());
// Force re-render of entire app
window.location.reload();
};
return (
<button onClick={handleToggle} className="language-switcher">
<span className="flag">{langInfo.flag}</span>
<span className="name">{langInfo.name}</span>
</button>
);
}
export default LanguageSwitcher;
Reloading the page ensures all components re-render with the new language.
Translation Keys Reference
Product Page
| Key | Turkish | Arabic |
|---|
seeOptions | Seçenekleri Görün | انظر الخيارات |
addToCart | Sepete Ekle | أضف إلى السلة |
productDescription | Ürün seçeneklerini inceleyin… | تعرف على خيارات المنتج… |
clickToOrder | Ürüne tıklayarak WhatsApp… | يمكنكم الطلب عبر الواتساب… |
| Key | Turkish | Arabic |
|---|
orderButton | Sipariş Ver | اطلب |
orderUnavailable | Servis Saatleri Dışındadır | خارج ساعات الخدمة |
Validation Messages
| Key | Turkish | Arabic |
|---|
minimumOrder | Minimum sepet tutarı TL’dir | الحد الأدنى للسلة ليرة تركية |
currentCart | Şu anki sepet: TL | السلة الحالية: ليرة تركية |
damacanaRestricted | Damacana siparişleri ‘dan sonra… | لا يتم قبول طلبات Demijohn بعد |
UI Elements
| Key | Turkish | Arabic |
|---|
welcomeMessage | Lütfen ilk siparişinizde… | يرجى عدم نسيان إضافة… |
understood | Anladım | فهمت |
scrollDown | Kaydır | تمرر |
Adding New Translations
To add a new translation key:
- Add to Turkish translations:
tr: {
translations: {
// ... existing translations
newKey: "Yeni Çeviri"
}
}
- Add to Arabic translations:
ar: {
translations: {
// ... existing translations
newKey: "ترجمة جديدة"
}
}
- Use in component:
import { t } from '../config/language';
<p>{t('newKey')}</p>
Adding New Languages
To add support for a new language:
export const LANGUAGES = {
tr: { /* ... */ },
ar: { /* ... */ },
en: {
code: 'en',
name: 'English',
flag: '🇬🇧',
translations: {
seeOptions: "See Options",
addToCart: "Add to Cart",
productDescription: "Browse product options and order.",
clickToOrder: "Click the product to order via WhatsApp",
orderButton: "Place Order",
orderUnavailable: "Outside Service Hours",
minimumOrder: "Minimum cart amount is {minimumAmount} TL",
currentCart: "Current cart: {amount} TL",
welcomeMessage: "Please don't forget to add your address on your first order. Thank you.",
understood: "Understood",
scrollDown: "Scroll"
}
}
};
Update the toggle function for multiple languages:
const languages = ['tr', 'ar', 'en'];
export const toggleLanguage = () => {
const currentIndex = languages.indexOf(currentLanguage);
const nextIndex = (currentIndex + 1) % languages.length;
currentLanguage = languages[nextIndex];
if (typeof window !== 'undefined') {
localStorage.setItem('suapp-language', currentLanguage);
}
return currentLanguage;
};
RTL Support (Arabic)
For proper Arabic display, add RTL support:
html[lang="ar"] {
direction: rtl;
}
html[lang="ar"] .modal-close-btn {
left: 1rem;
right: auto;
}
html[lang="ar"] .quantity-controls {
flex-direction: row-reverse;
}
Set the lang attribute dynamically:
import { getCurrentLanguage } from './config/language';
useEffect(() => {
document.documentElement.setAttribute('lang', getCurrentLanguage());
}, []);
Integration Examples
src/components/OrderButton.js
import { t } from '../config/language';
const OrderButton = () => {
const { getTotalItems, getTotalPrice } = useCart();
const totalItems = getTotalItems();
const totalPrice = getTotalPrice();
return (
<button className="order-button">
{t('orderButton')} - {totalPrice.toFixed(2)} TL
</button>
);
};
Product Modal with Translation
src/components/ProductModal.js
import { t } from '../config/language';
const ProductModal = ({ product, isOpen, onClose }) => {
return (
<div className="modal-content">
<div className="modal-header">
<h2>{product.name}</h2>
<p>{t('productDescription')}</p>
</div>
<div className="modal-footer">
<p>💬 {t('clickToOrder')}</p>
</div>
</div>
);
};
Validation Messages
import { t } from '../config/language';
import { ORDER_LIMITS } from '../config/orderLimits';
function ValidationMessage({ totalPrice }) {
if (totalPrice < ORDER_LIMITS.minimumOrderAmount) {
return (
<div className="validation-error">
{t('minimumOrder', { minimumAmount: ORDER_LIMITS.minimumOrderAmount })}
<br />
{t('currentCart', { amount: totalPrice.toFixed(2) })}
</div>
);
}
return null;
}
Best Practices
Consistent Keys
Use descriptive, consistent translation keys across the application.
Fallback Text
Always provide fallback to default language if translation is missing.
Parameter Naming
Use clear parameter names like {minimumAmount} instead of {0} or {x}.
Context Matters
Provide context-appropriate translations, not just literal word-for-word translations.
LocalStorage Persistence
The language preference is saved automatically:
// Saved on toggle
localStorage.setItem('suapp-language', 'ar');
// Retrieved on page load
const savedLang = localStorage.getItem('suapp-language');
Language preference persists across browser sessions using localStorage.
Troubleshooting
Translations Not Updating
// Force reload after language change
window.location.reload();
Missing Translation
// The t() function falls back to the key itself
const text = t('nonExistentKey');
// Returns: "nonExistentKey"
Clear Language Cache
localStorage.removeItem('suapp-language');
window.location.reload();
WhatsApp Ordering
See how multi-language support integrates with order messages
Product Catalog
Learn about product display with translations