Skip to content

Commit

Permalink
fix: fixed translation bug for custom rules (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
7Sageer committed Feb 25, 2025
1 parent 4431513 commit 8c92bd8
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const IP_RULE_SETS = UNIFIED_RULES.reduce((acc, rule) => {
// Helper function to get outbounds based on selected rule names
export function getOutbounds(selectedRuleNames) {
if (!selectedRuleNames || !Array.isArray(selectedRuleNames)) {
return []; // or handle this case as appropriate for your use case
return [];
}
return UNIFIED_RULES
.filter(rule => selectedRuleNames.includes(rule.name))
Expand Down
17 changes: 8 additions & 9 deletions src/htmlBuilder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UNIFIED_RULES, PREDEFINED_RULE_SETS } from './config.js';
import { generateStyles } from './style.js';
import { t, getCurrentLang} from './i18n/index.js';
import { t } from './i18n/index.js';

export function generateHtml(xrayUrl, singboxUrl, clashUrl, surgeUrl, baseUrl) {
return `
Expand Down Expand Up @@ -132,10 +132,10 @@ const generateForm = () => `

const generateSubscribeLinks = (xrayUrl, singboxUrl, clashUrl, surgeUrl, baseUrl) => `
<div class="mt-5">
${generateLinkInput('Xray(Base64):', 'xrayLink', xrayUrl)}
${generateLinkInput('SingBox:', 'singboxLink', singboxUrl)}
${generateLinkInput('Clash:', 'clashLink', clashUrl)}
${generateLinkInput('Surge/Surfboard:', 'surgeLink', surgeUrl)}
${generateLinkInput('Xray Link (Base64):', 'xrayLink', xrayUrl)}
${generateLinkInput('SingBox Link:', 'singboxLink', singboxUrl)}
${generateLinkInput('Clash Link:', 'clashLink', clashUrl)}
${generateLinkInput('Surge Link:', 'surgeLink', surgeUrl)}
<div class="mb-3">
<label for="customShortCode" class="form-label">${t('customPath')}</label>
<div class="input-group flex-nowrap">
Expand Down Expand Up @@ -498,11 +498,10 @@ const submitFormFunction = () => `
}));
const configParam = configId ? \`&configId=\${configId}\` : '';
const langParam = \`&lang=${getCurrentLang()}\`;
const xrayUrl = \`\${window.location.origin}/xray?config=\${encodeURIComponent(inputString)}\${configParam}\`;
const singboxUrl = \`\${window.location.origin}/singbox?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\${langParam}\`;
const clashUrl = \`\${window.location.origin}/clash?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\${langParam}\`;
const surgeUrl = \`\${window.location.origin}/surge?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\${langParam}\`;
const singboxUrl = \`\${window.location.origin}/singbox?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\`;
const clashUrl = \`\${window.location.origin}/clash?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\`;
const surgeUrl = \`\${window.location.origin}/surge?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\${configParam}\`;
document.getElementById('xrayLink').value = xrayUrl;
document.getElementById('singboxLink').value = singboxUrl;
document.getElementById('clashLink').value = clashUrl;
Expand Down
158 changes: 83 additions & 75 deletions src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,79 +154,79 @@ const translations = {
'GLOBAL': 'GLOBAL'
}
},
'ar': {
missingInput: 'معلمة الإدخال مفقودة',
missingConfig: 'معلمة التكوين مفقودة',
missingUrl: 'معلمة URL مفقودة',
shortUrlNotFound: 'لم يتم العثور على الرابط المختصر',
internalError: 'خطأ داخلي في الخادم',
notFound: 'غير موجود',
invalidFormat: 'تنسيق غير صالح: ',
defaultRules: ['حظر الإعلانات', 'خدمات جوجل', 'وسائط أجنبية', 'تيليجرام'],
configValidationError: 'خطأ في التحقق من صحة التكوين: ',
pageDescription: 'Sublink Worker - محول روابط الاشتراك',
pageKeywords: 'رابط الاشتراك,محول,Xray,SingBox,Clash,Surge',
pageTitle: 'Sublink Worker - محول روابط الاشتراك',
ogTitle: 'Sublink Worker - محول روابط الاشتراك',
ogDescription: 'محول قوي لروابط الاشتراك يدعم تنسيقات عملاء متعددة',
shareUrls: 'مشاركة الروابط',
urlPlaceholder: 'أدخل روابط الاشتراك الخاصة بك هنا...',
advancedOptions: 'خيارات متقدمة',
baseConfigSettings: 'إعدادات التكوين الأساسي',
baseConfigTooltip: 'قم بتخصيص التكوين الأساسي الخاص بك هنا',
saveConfig: 'حفظ التكوين',
clearConfig: 'مسح التكوين',
convert: 'تحويل',
clear: 'مسح',
customPath: 'مسار مخصص',
savedPaths: 'المسارات المحفوظة',
shortenLinks: 'إنشاء روابط قصيرة',
ruleSelection: 'اختيار القواعد',
ruleSelectionTooltip: 'حدد مجموعات القواعد المطلوبة',
custom: 'مخصص',
minimal: 'الحد الأدنى',
balanced: 'متوازن',
comprehensive: 'شامل',
addCustomRule: 'إضافة قاعدة مخصصة',
customRuleOutboundName: 'اسم المخرج*',
customRuleGeoSite: 'قواعد Geo-Site',
customRuleGeoSiteTooltip: 'قواعد SingBox Site تأتي من https://github.com/lyc8503/sing-box-rules، مما يعني أن قواعدك المخصصة يجب أن تكون في هذا المستودع',
customRuleGeoSitePlaceholder: 'مثال: google,anthropic',
customRuleGeoIP: 'قواعد Geo-IP',
customRuleGeoIPTooltip: 'قواعد SingBox IP تأتي من https://github.com/lyc8503/sing-box-rules، مما يعني أن قواعدك المخصصة يجب أن تكون في هذا المستودع',
customRuleGeoIPPlaceholder: 'مثال: private,cn',
customRuleDomainSuffix: 'لاحقة النطاق',
customRuleDomainSuffixPlaceholder: 'لواحق النطاق (مفصولة بفواصل)',
customRuleDomainKeyword: 'كلمة مفتاحية للنطاق',
customRuleDomainKeywordPlaceholder: 'الكلمات المفتاحية للنطاق (مفصولة بفواصل)',
'fa': {
missingInput: 'پارامتر ورودی وجود ندارد',
missingConfig: 'پارامتر پیکربندی وجود ندارد',
missingUrl: 'پارامتر URL وجود ندارد',
shortUrlNotFound: 'لینک کوتاه پیدا نشد',
internalError: 'خطای داخلی سرور',
notFound: 'یافت نشد',
invalidFormat: 'فرمت نامعتبر: ',
defaultRules: ['مسدودسازی تبلیغات', 'سرویس‌های گوگل', 'رسانه‌های خارجی', 'تلگرام'],
configValidationError: 'خطای اعتبارسنجی پیکربندی: ',
pageDescription: 'Sublink Worker - مبدل لینک اشتراک',
pageKeywords: 'لینک اشتراک,مبدل,Xray,SingBox,Clash,Surge',
pageTitle: 'Sublink Worker - مبدل لینک اشتراک',
ogTitle: 'Sublink Worker - مبدل لینک اشتراک',
ogDescription: 'یک مبدل قدرتمند لینک اشتراک با پشتیبانی از فرمت‌های مختلف',
shareUrls: 'اشتراک‌گذاری لینک‌ها',
urlPlaceholder: 'لینک‌های اشتراک خود را اینجا وارد کنید...',
advancedOptions: 'گزینه‌های پیشرفته',
baseConfigSettings: 'تنظیمات پیکربندی پایه',
baseConfigTooltip: 'پیکربندی پایه خود را اینجا سفارشی کنید',
saveConfig: 'ذخیره پیکربندی',
clearConfig: 'پاک کردن پیکربندی',
convert: 'تبدیل',
clear: 'پاک کردن',
customPath: 'مسیر سفارشی',
savedPaths: 'مسیرهای ذخیره شده',
shortenLinks: 'ایجاد لینک‌های کوتاه',
ruleSelection: 'انتخاب قوانین',
ruleSelectionTooltip: 'مجموعه قوانین مورد نظر خود را انتخاب کنید',
custom: 'سفارشی',
minimal: 'حداقل',
balanced: 'متعادل',
comprehensive: 'جامع',
addCustomRule: 'افزودن قانون سفارشی',
customRuleOutboundName: 'نام خروجی*',
customRuleGeoSite: 'قوانین Geo-Site',
customRuleGeoSiteTooltip: 'قوانین SingBox Site از https://github.com/lyc8503/sing-box-rules می‌آیند، به این معنی که قوانین سفارشی شما باید در آن مخزن باشد',
customRuleGeoSitePlaceholder: 'برای مثال: google,anthropic',
customRuleGeoIP: 'قوانین Geo-IP',
customRuleGeoIPTooltip: 'قوانین SingBox IP از https://github.com/lyc8503/sing-box-rules می‌آیند، به این معنی که قوانین سفارشی شما باید در آن مخزن باشد',
customRuleGeoIPPlaceholder: 'برای مثال: private,cn',
customRuleDomainSuffix: 'پسوند دامنه',
customRuleDomainSuffixPlaceholder: 'پسوندهای دامنه (با کاما جدا شده)',
customRuleDomainKeyword: 'کلمه کلیدی دامنه',
customRuleDomainKeywordPlaceholder: 'کلمات کلیدی دامنه (با کاما جدا شده)',
customRuleIPCIDR: 'IP CIDR',
customRuleIPCIDRPlaceholder: 'IP CIDR (مفصولة بفواصل)',
customRuleProtocol: 'نوع البروتوكول',
customRuleProtocolTooltip: 'قواعد البروتوكول لأنواع محددة من حركة المرور. مزيد من التفاصيل: https://sing-box.sagernet.org/configuration/route/sniff/',
customRuleProtocolPlaceholder: 'البروتوكولات (مفصولة بفواصل، مثال: http,ssh,dns)',
removeCustomRule: 'إزالة',
customRuleIPCIDRPlaceholder: 'IP CIDR (با کاما جدا شده)',
customRuleProtocol: 'نوع پروتکل',
customRuleProtocolTooltip: 'قوانین پروتکل برای انواع خاص ترافیک. جزئیات بیشتر: https://sing-box.sagernet.org/configuration/route/sniff/',
customRuleProtocolPlaceholder: 'پروتکل‌ها (با کاما جدا شده، مثلاً: http,ssh,dns)',
removeCustomRule: 'حذف',
outboundNames: {
'Auto Select': '⚡ تحديد تلقائي',
'Node Select': '🚀 اختيار العقدة',
'Fall Back': '🐟 العودة',
'Ad Block': '🛑 حظر الإعلانات',
'AI Services': '💬 خدمات الذكاء الاصطناعي',
'Bilibili': '📺 بيلي بيلي',
'Youtube': '📹 يوتيوب',
'Google': '🔍 خدمات جوجل',
'Private': '🏠 شبكة خاصة',
'Location:CN': '🔒 خدمات الصين',
'Telegram': '📲 تيليجرام',
'Github': '🐱 جيثب',
'Microsoft': 'Ⓜ️ خدمات مايكروسوفت',
'Apple': '🍏 خدمات آبل',
'Social Media': '🌐 وسائل التواصل الاجتماعي',
'Streaming': '🎬 بث الوسائط',
'Gaming': '🎮 منصة الألعاب',
'Education': '📚 موارد تعليمية',
'Financial': '💰 خدمات مالية',
'Cloud Services': '☁️ خدمات سحابية',
'Non-China': '🌐 خارج الصين',
'Auto Select': '⚡ انتخاب خودکار',
'Node Select': '🚀 انتخاب نود',
'Fall Back': '🐟 فال بک',
'Ad Block': '🛑 مسدودسازی تبلیغات',
'AI Services': '💬 سرویس‌های هوش مصنوعی',
'Bilibili': '📺 بیلی‌بیلی',
'Youtube': '📹 یوتیوب',
'Google': '🔍 سرویس‌های گوگل',
'Private': '🏠 شبکه خصوصی',
'Location:CN': '🔒 سرویس‌های چین',
'Telegram': '📲 تلگرام',
'Github': '🐱 گیت‌هاب',
'Microsoft': 'Ⓜ️ سرویس‌های مایکروسافت',
'Apple': '🍏 سرویس‌های اپل',
'Social Media': '🌐 شبکه‌های اجتماعی',
'Streaming': '🎬 استریمینگ',
'Gaming': '🎮 پلتفرم بازی',
'Education': '📚 منابع آموزشی',
'Financial': '💰 سرویس‌های مالی',
'Cloud Services': '☁️ سرویس‌های ابری',
'Non-China': '🌐 خارج از چین',
'GLOBAL': 'GLOBAL'
}
}
Expand All @@ -242,20 +242,28 @@ export function setLanguage(lang) {
currentLang = lang;
} else if(checkStartsWith(lang, 'en')) {
currentLang = 'en-US';
} else if(checkStartsWith(lang, 'ar')) {
currentLang = 'ar';
} else if(checkStartsWith(lang, 'fa')) {
currentLang = 'fa';
} else {
currentLang = 'zh-CN';
}
}

// 获取翻译
// 获取翻译,支持嵌套键值访问
export function t(key) {
const keys = key.split('.');
let value = translations[currentLang];

// 逐级查找翻译值
for (const k of keys) {
value = value?.[k];
if (value === undefined) return key;
if (value === undefined) {
if (checkStartsWith(key, 'outboundNames.')) {
return key.split('.')[1];
}
// 找不到翻译时返回原始键名
return key;
}
}
return value;
}
Expand Down

0 comments on commit 8c92bd8

Please sign in to comment.