feat: split localize in to files

This commit is contained in:
tiennm99 committed 2025-04-27 20:02:29 +07:00
1 parent f7c504219a
commit f70a9246f7
3 files changed
+72 -127

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
{
"gameTitle": "NIGHT NINJA: TWILIGHT VOYAGE",
"startGame": "START GAME",
"levelSelect": "LEVEL SELECT",
"settings": "SETTINGS",
"gameDescription": "Guide the ninja through the shadows.\nAvoid light at all costs.\nRescue the princess... if you can.",
"instructions": "Use arrow keys, WASD, or tap to move.",
"languageSettings": "Language",
"english": "English",
"vietnamese": "Vietnamese",
"back": "Back",
"levelSelectTitle": "SELECT LEVEL",
"levelNumber": "Level",
"lives": "Lives: ",
"level": "Level: ",
"pause": "PAUSE",
"menu": "MENU",
"paused": "PAUSED",
"resume": "RESUME",
"restartLevel": "RESTART LEVEL",
"detected": "You have been detected!",
"playAgain": "PLAY AGAIN",
"princessDetected": "The princess has detected the ninja! The entire palace is lit up!",
"gameOver": "GAME OVER",
"theEnd": "THE END",
"caughtInLight": "You were caught in the light!",
"ninjaFailed": "Unfortunately, in this life, the ninja cannot rescue the princess.",
"tryAgain": "TRY AGAIN",
"mainMenu": "MAIN MENU"
}
+30
View File
@@ -0,0 +1,30 @@
{
"gameTitle": "NINJA ĐÊM: HÀNH TRÌNH HOÀNG HÔN",
"startGame": "BẮT ĐẦU CHƠI",
"levelSelect": "CHỌN CẤP ĐỘ",
"settings": "CÀI ĐẶT",
"gameDescription": "Dẫn dắt ninja qua bóng tối.\nTránh ánh sáng bằng mọi giá.\nCứu công chúa... nếu bạn có thể.",
"instructions": "Sử dụng phím mũi tên, WASD, hoặc chạm để di chuyển.",
"languageSettings": "Ngôn ngữ",
"english": "Tiếng Anh",
"vietnamese": "Tiếng Việt",
"back": "Quay lại",
"levelSelectTitle": "CHỌN CẤP ĐỘ",
"levelNumber": "Cấp độ",
"lives": "Mạng: ",
"level": "Cấp độ: ",
"pause": "TẠM DỪNG",
"menu": "MENU",
"paused": "TẠM DỪNG",
"resume": "TIẾP TỤC",
"restartLevel": "CHƠI LẠI CẤP ĐỘ",
"detected": "Bạn đã bị phát hiện!",
"playAgain": "CHƠI LẠI",
"princessDetected": "Công chúa phát hiện ra ninja! Toàn bộ cung điện sáng đèn!",
"gameOver": "GAME KẾT THÚC",
"theEnd": "KẾT THÚC",
"caughtInLight": "Bạn đã bị bắt trong ánh sáng!",
"ninjaFailed": "Thật tiếc, kiếp này ninja không thể giải cứu công chúa rồi.",
"tryAgain": "THỬ LẠI",
"mainMenu": "MENU CHÍNH"
}
+12 -127
View File
@@ -1,142 +1,27 @@
// Localization system for Night Ninja: Twilight Voyage
// Supports English and Vietnamese languages
// Import language files
import enTranslations from './locales/en.json';
import viTranslations from './locales/vi.json';
// Default language is Vietnamese
let currentLanguage = 'vi';
// Text data for all UI elements in the game
// Store translations in a map
const localizationData = {
// Main Menu
'gameTitle': {
'en': 'NIGHT NINJA: TWILIGHT VOYAGE',
'vi': 'NINJA ĐÊM: HÀNH TRÌNH HOÀNG HÔN'
},
'startGame': {
'en': 'START GAME',
'vi': 'BẮT ĐẦU CHƠI'
},
'levelSelect': {
'en': 'LEVEL SELECT',
'vi': 'CHỌN CẤP ĐỘ'
},
'settings': {
'en': 'SETTINGS',
'vi': 'CÀI ĐẶT'
},
'gameDescription': {
'en': 'Guide the ninja through the shadows.\nAvoid light at all costs.\nRescue the princess... if you can.',
'vi': 'Dẫn dắt ninja qua bóng tối.\nTránh ánh sáng bằng mọi giá.\nCứu công chúa... nếu bạn có thể.'
},
'instructions': {
'en': 'Use arrow keys, WASD, or tap to move.',
'vi': 'Sử dụng phím mũi tên, WASD, hoặc chạm để di chuyển.'
},
// Settings Menu
'languageSettings': {
'en': 'Language',
'vi': 'Ngôn ngữ'
},
'english': {
'en': 'English',
'vi': 'Tiếng Anh'
},
'vietnamese': {
'en': 'Vietnamese',
'vi': 'Tiếng Việt'
},
'back': {
'en': 'Back',
'vi': 'Quay lại'
},
// Level Select
'levelSelectTitle': {
'en': 'SELECT LEVEL',
'vi': 'CHỌN CẤP ĐỘ'
},
'levelNumber': {
'en': 'Level',
'vi': 'Cấp độ'
},
// Game UI
'lives': {
'en': 'Lives: ',
'vi': 'Mạng: '
},
'level': {
'en': 'Level: ',
'vi': 'Cấp độ: '
},
'pause': {
'en': 'PAUSE',
'vi': 'TẠM DỪNG'
},
'menu': {
'en': 'MENU',
'vi': 'MENU'
},
'paused': {
'en': 'PAUSED',
'vi': 'TẠM DỪNG'
},
'resume': {
'en': 'RESUME',
'vi': 'TIẾP TỤC'
},
'restartLevel': {
'en': 'RESTART LEVEL',
'vi': 'CHƠI LẠI CẤP ĐỘ'
},
'detected': {
'en': 'You have been detected!',
'vi': 'Bạn đã bị phát hiện!'
},
'playAgain': {
'en': 'PLAY AGAIN',
'vi': 'CHƠI LẠI'
},
'princessDetected': {
'en': 'The princess has detected the ninja! The entire palace is lit up!',
'vi': 'Công chúa phát hiện ra ninja! Toàn bộ cung điện sáng đèn!'
},
// Game Over
'gameOver': {
'en': 'GAME OVER',
'vi': 'GAME KẾT THÚC'
},
'theEnd': {
'en': 'THE END',
'vi': 'KẾT THÚC'
},
'caughtInLight': {
'en': 'You were caught in the light!',
'vi': 'Bạn đã bị bắt trong ánh sáng!'
},
'ninjaFailed': {
'en': 'Unfortunately, in this life, the ninja cannot rescue the princess.',
'vi': 'Thật tiếc, kiếp này ninja không thể giải cứu công chúa rồi.'
},
'tryAgain': {
'en': 'TRY AGAIN',
'vi': 'THỬ LẠI'
},
'mainMenu': {
'en': 'MAIN MENU',
'vi': 'MENU CHÍNH'
}
'en': enTranslations,
'vi': viTranslations
};
// Function to get text in the current language
function getText(key) {
if (localizationData[key] && localizationData[key][currentLanguage]) {
return localizationData[key][currentLanguage];
if (localizationData[currentLanguage] && localizationData[currentLanguage][key]) {
return localizationData[currentLanguage][key];
}
// Fallback to English if the key or language is not found
if (localizationData[key] && localizationData[key]['en']) {
return localizationData[key]['en'];
// Fallback to English if the key is not found in current language
if (localizationData['en'] && localizationData['en'][key]) {
return localizationData['en'][key];
}
// Return the key itself if no translation is found
return key;