Files
product-slip/slips/static/slips/js/i18n.js
diaco cb8fd593c0 Rename app title to Lithium | Print Label (#10)
Co-authored-by: Cursor <cursoragent@cursor.com>
Reviewed-on: #10
Co-authored-by: diaco <dyaco8464@yahoo.com>
Co-committed-by: diaco <dyaco8464@yahoo.com>
2026-10-04 07:25:05 +00:00

152 lines
5.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const translations = {
'en': {
'app_title': 'Lithium | Print Label',
'data_entry': 'Data Entry',
'print_queue': 'Print Queue',
'calibrate': 'Calibrate',
'new_order': 'New Order',
'product': 'Product',
'add_product': '+ Add New Product',
'product_code': 'Product Code',
'description': 'Description',
'default_weight': 'Default Weight',
'save': 'Save',
'cancel': 'Cancel',
'batch_number': 'Batch #',
'date': 'Date',
'next_control': 'Next Control Date',
'net_weight': 'Net Weight (kg)',
'total_weight': 'Total Weight (kg)',
'canister_weight': 'Canister Weight (kg)',
'canisters_per_box': 'Canisters per Box',
'labels_preview': 'Labels Generated',
'canisters': 'Canisters',
'boxes': 'Boxes',
'canisters_unit': 'Canisters',
'boxes_unit': 'Boxes',
'pages_unit': 'Page(s)',
'preview_pages': 'pages',
'pages_needed': 'Pages Needed',
'total_pages': 'Pages',
'status_pending': 'Pending',
'add_to_queue': 'Add to Print Queue',
'recent_orders': 'Recent Orders',
'status': 'Status',
'no_orders': 'No orders yet',
'no_pending_orders': 'No pending orders to print.',
'print': 'Print',
'mark_done': 'Mark Done',
'print_history': 'Print History',
'printed_at': 'Printed At',
'no_history': 'No print history'
},
'fa': {
'app_title': 'لیتیوم |‌ پرینت لیبل',
'data_entry': 'ثبت اطلاعات',
'print_queue': 'صف چاپ',
'calibrate': 'کالیبراسیون',
'new_order': 'سفارش جدید',
'product': 'محصول',
'add_product': '+ افزودن محصول جدید',
'product_code': 'کد محصول',
'description': 'شرح',
'default_weight': 'وزن پیش‌فرض',
'save': 'ذخیره',
'cancel': 'لغو',
'batch_number': 'شماره بچ',
'date': 'تاریخ',
'next_control': 'تاریخ کنترل بعدی',
'net_weight': 'وزن خالص (کیلوگرم)',
'total_weight': 'وزن کل (کیلوگرم)',
'canister_weight': 'وزن گالن (کیلوگرم)',
'canisters_per_box': 'تعداد گالن در هر کارتن',
'labels_preview': 'برچسب‌های تولیدی',
'canisters': 'تعداد گالن',
'boxes': 'تعداد کارتن',
'canisters_unit': 'گالن',
'boxes_unit': 'کارتن',
'pages_unit': 'صفحه',
'preview_pages': 'صفحه',
'pages_needed': 'تعداد صفحات',
'total_pages': 'صفحات',
'status_pending': 'در انتظار',
'add_to_queue': 'افزودن به صف چاپ',
'recent_orders': 'سفارشات اخیر',
'status': 'وضعیت',
'no_orders': 'سفارشی ثبت نشده',
'no_pending_orders': 'سفارشی در انتظار چاپ نیست.',
'print': 'چاپ',
'mark_done': 'چاپ شد',
'print_history': 'سابقه چاپ',
'printed_at': 'زمان چاپ',
'no_history': 'سابقه‌ای وجود ندارد'
}
};
let currentLang = localStorage.getItem('slip_lang') || 'en';
let currentTheme = localStorage.getItem('slip_theme') || 'light';
function applyTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
const label = document.getElementById('theme-label');
if (label) {
// show the theme you'll switch to
label.textContent = theme === 'light' ? '🌙' : '☀️';
}
}
function toggleTheme() {
currentTheme = currentTheme === 'light' ? 'dark' : 'light';
localStorage.setItem('slip_theme', currentTheme);
applyTheme(currentTheme);
}
function applyLanguage(lang) {
document.documentElement.lang = lang;
document.documentElement.dir = lang === 'fa' ? 'rtl' : 'ltr';
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.getAttribute('data-i18n');
if (translations[lang][key]) {
el.textContent = translations[lang][key];
}
});
const toggleBtn = document.getElementById('lang-label');
if (toggleBtn) {
toggleBtn.textContent = lang === 'en' ? '🇮🇷 FA' : '🇬🇧 EN';
}
if (typeof window.updateLabelsPreview === 'function') {
window.updateLabelsPreview();
}
}
function toggleLanguage() {
currentLang = currentLang === 'en' ? 'fa' : 'en';
localStorage.setItem('slip_lang', currentLang);
applyLanguage(currentLang);
}
// Common Toast notification
function showToast(message, isError = false) {
const toast = document.getElementById('toast');
if (!toast) return;
toast.textContent = message;
if (isError) {
toast.classList.add('error');
} else {
toast.classList.remove('error');
}
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 3000);
}
// Initialize on load
document.addEventListener('DOMContentLoaded', () => {
applyTheme(currentTheme);
applyLanguage(currentLang);
});