Browse Source

Updating translation system for nested keys

master
Mobius K 3 years ago
parent
commit
1a4b9fff01
  1. 6
      src/routes/index.pug
  2. 145
      src/scripts/i18n.js
  3. 22
      src/templates/major-device.pug
  4. 8
      src/templates/major-service.pug
  5. 108
      src/templates/minor-device.pug

6
src/routes/index.pug

@ -11,11 +11,11 @@ block content
input#bluetoothClass.text-center(type="text", readonly, onclick="copyBluetoothClassField()")
span.helper-text(i18n="clickToCopy")
h2(i18n="majorService")
h2(i18n="majorService.group")
include ../templates/major-service
h3(i18n="majorDevice")
h3(i18n="majorDevice.group")
include ../templates/major-device
h4(i18n="minorDevice")
h4(i18n="minorDevice.group")
include ../templates/minor-device

145
src/scripts/i18n.js

@ -4,38 +4,101 @@ const languageTranslations = {
en: {
bluetoothClass: "BlueTooth class",
builtBy: "Built by",
copy: "Copy",
majorService: "Major service",
majorServiceInformation: "Information",
majorServiceTelephony: "Telephony",
majorServiceAudio: "Audio",
majorServiceObjectTransfer: "Object transfer",
majorServiceCapturing: "Capturing",
majorServiceRendering: "Rendering",
majorServiceNetworking: "Networking",
majorServicePositioning: "Positioning",
majorServiceLimitedDiscovery: "Limited discovery",
majorDevice: "Major device",
majorDeviceUncategorized: "Uncategorized",
majorDeviceMiscellaneous: "Miscellaneous",
majorDeviceToy: "Toy",
majorDeviceWearable: "Wearable",
majorDeviceImaging: "Imaging",
majorDevicePeripheral: "Peripheral",
majorDeviceAudioVideo: "Audio / Video",
majorDeviceNetworkAccessPoint: "Network access point",
majorDevicePhone: "Phone",
majorDeviceComputer: "Computer",
minorDevice: "Minor device",
minorDeviceToyGame: "Game",
minorDeviceToyController: "Controller",
minorDeviceToyDoll: "Doll",
minorDeviceToyVehicle: "Vehicle",
minorDeviceToyRobot: "Robot",
clickToCopy: "Click to copy",
majorService: {
group: "Major service",
Information: "Information",
Telephony: "Telephony",
Audio: "Audio",
Transfer: "Transfer",
Capturing: "Capturing",
Rendering: "Rendering",
AccessPoint: "Access point",
Positioning: "Positioning",
LimitedDiscovery: "Limited discovery",
},
majorDevice: {
group: "Major device",
Uncategorized: "Uncategorized",
Miscellaneous: "Miscellaneous",
Toy: "Toy",
Wearable: "Wearable",
Imaging: "Imaging",
Peripheral: "Peripheral",
AudioVideo: "Media",
AccessPoint: "Access point",
Phone: "Phone",
Computer: "Computer",
},
minorDevice: {
group: "Minor device",
None: "No minor devices",
Toy : {
Game: "Game",
Controller: "Controller",
Doll: "Doll",
Vehicle: "Vehicle",
Robot: "Robot",
},
Wearable: {
Watch: "Watch",
Pager: "Pager",
Jacket: "Jacket",
Helmet: "Helmet",
Glasses: "Glasses",
},
Imaging: {
Display: "Display",
Camera: "Camera",
Scanner: "Scanner",
Printer: "Printer",
},
Peripheral: {
Keyboard: "Keyboard",
Pointer: "Pointer",
Uncategorized: "Uncategorized",
Joystick: "Joystick",
Gamepad: "Gamepad",
RemoteControl: "Remote control",
Sensor: "Sensor",
Digitizer: "Digitizer",
CardReader: "Card reader",
},
AudioVideo: {
Uncategorized: "Uncategorized",
Headset: "Headset",
Microphone: "Microphone",
Loudspeaker: "Loudspeaker",
Headphones: "Headphones",
CarAudio: "Car audio",
VideoCamera: "Video camera",
Monitor: "Monitor",
Conferencing: "Conferencing",
},
AccessPoint: {
Available: "Available",
Level1: "1-17% use",
Level2: "17-33% use",
Level3: "33-50% use",
Level4: "50-67% use",
Level5: "67-83% use",
Level6: "83-99% use",
Unavailable: "Unavailable",
},
Phone: {
Uncategorized: "Uncategorized",
Cell: "Cell",
Cordless: "Cordless",
},
Computer: {
Uncategorized: "Uncategorized",
Desktop: "Desktop",
Server: "Server",
Laptop: "Laptop",
PDA: "PDA",
Watch: "Watch",
},
},
},
es: {
builtBy: "Construido por",
@ -75,10 +138,22 @@ function languageChange(language) {
/**
* Return translated text based on key-value matching above
*
* @param key Translation specifier in above translation map
* @param path Translation specifier in above translation map, like majorService.title
*/
function translateKey(key) {
return languageTranslations[languageCurrent][key];
function translateKey(path) {
if (path == null) {
return undefined;
}
let translation = languageTranslations[languageCurrent];
path.split(".").forEach((key) => {
if (translation != null) {
translation = translation[key];
}
});
return translation;
}
/**

22
src/templates/major-device.pug

@ -1,15 +1,15 @@
-
const majorDevices = {
"Uncategorized": 0x1F00,
"Toy": 0x0800,
"Wearable": 0x0700,
"Imaging": 0x0600,
"Peripheral": 0x0500,
"AudioVideo": 0x0400,
"NetworkAccessPoint": 0x0300,
"Phone": 0x0200,
"Computer": 0x0100,
"Miscellaneous": 0x0000,
"Uncategorized": 0x1F00,
"Toy": 0x0800,
"Wearable": 0x0700,
"Imaging": 0x0600,
"Peripheral": 0x0500,
"AudioVideo": 0x0400,
"AccessPoint": 0x0300,
"Phone": 0x0200,
"Computer": 0x0100,
"Miscellaneous": 0x0000,
}
.row
@ -17,4 +17,4 @@
.col.s12.m6.l4
label(for="majorDevice" + key)
input.with-gap(type="radio", name="majorDevice", id="majorDevice" + key, value=value)
span(i18n="majorDevice" + key)
span(i18n="majorDevice." + key)

8
src/templates/major-service.pug

@ -3,12 +3,12 @@
"Information": 0x800000,
"Telephony": 0x400000,
"Audio": 0x200000,
"ObjectTransfer": 0x100000,
"Transfer": 0x100000,
"Capturing": 0x080000,
"Rendering": 0x040000,
"Networking": 0x020000,
"AccessPoint": 0x020000,
"Positioning": 0x010000,
"LimitedDiscovery": 0x002000,
"LimitedDiscovery": 0x002000
}
.row
@ -16,4 +16,4 @@
.col.s12.m6.l4
label(for="majorService" + key)
input(type="checkbox", id="majorService" + key, value=value)
span(i18n="majorService" + key)
span(i18n="majorService." + key)

108
src/templates/minor-device.pug

@ -8,11 +8,11 @@
"Robot": 0x04,
},
"Wearable": {
"Wrist Watch": 0x00,
"Pager": 0x00,
"Jacket": 0x00,
"Helmet": 0x00,
"Glasses": 0x00,
"Watch": 0x00,
"Pager": 0x00,
"Jacket": 0x00,
"Helmet": 0x00,
"Glasses": 0x00,
},
"Imaging": {
"Display": 0x00,
@ -21,78 +21,62 @@
"Printer": 0x00,
},
"Peripheral": {
"Not keyboard or pointer": 0x00,
"Keyboard": 0x00,
"Pointing device": 0x00,
"Keyboard and pointer": 0x00,
"Uncategorized": 0x00,
"Joystick": 0x00,
"Gamepad": 0x00,
"Remote control": 0x00,
"Sensing device": 0x00,
"Digitizer tablet": 0x00,
"Card Reader ": 0x00,
"Keyboard": 0x00,
"Pointer": 0x00,
"Uncategorized": 0x00,
"Joystick": 0x00,
"Gamepad": 0x00,
"RemoteControl": 0x00,
"Sensor": 0x00,
"Digitizer": 0x00,
"CardReader": 0x00,
},
"AudioVideo": {
"Uncategorized": 0x00,
"Wearable headset": 0x00,
"Hands-free": 0x00,
"Microphone": 0x00,
"Loudspeaker": 0x00,
"Headphones": 0x00,
"Portable audio": 0x00,
"Car audio": 0x00,
"Set-top box": 0x00,
"HiFi Audio": 0x00,
"VCR": 0x00,
"Video Camera": 0x00,
"Camcorder": 0x00,
"Video Monitor": 0x00,
"Video Display and Loudspeaker": 0x00,
"Video conferencing": 0x00,
"Gaming / Toy": 0x00,
"Uncategorized": 0x00,
"Headset": 0x00,
"Microphone": 0x00,
"Loudspeaker": 0x00,
"Headphones": 0x00,
"CarAudio": 0x00,
"VideoCamera": 0x00,
"Monitor": 0x00,
"Conferencing": 0x00,
},
"NetworkAccessPoint": {
"Fully available": 0x00,
"1 - 17% utilized": 0x00,
"17 - 33% utilized": 0x00,
"33 - 50% utilized": 0x00,
"50 - 67% utilized": 0x00,
"67 - 83% utilized": 0x00,
"83 - 99% utilized": 0x00,
"No service available": 0x00,
"AccessPoint": {
"Available": 0x00,
"Level1": 0x00,
"Level2": 0x00,
"Level3": 0x00,
"Level4": 0x00,
"Level5": 0x00,
"Level6": 0x00,
"Unavailable": 0x00,
},
"Phone": {
"Uncategorized": 0x00,
"Cellular": 0x00,
"Cordless": 0x00,
"Smart phone": 0x00,
"Wired modem or voice gateway": 0x00,
"Common ISDN Access": 0x00,
"Uncategorized": 0x00,
"Cell": 0x00,
"Cordless": 0x00,
},
"Computer": {
"Uncategorized": 0x00,
"Desktop": 0x00,
"Server-class": 0x00,
"Laptop": 0x00,
"Handheld PC/PDA": 0x00,
"Palm sized PC/PDA": 0x00,
"Wearable computer (watch)": 0x00,
"Uncategorized": 0x00,
"Desktop": 0x00,
"Server": 0x00,
"Laptop": 0x00,
"PDA": 0x00,
"Watch": 0x00,
},
"Miscellaneous": {},
"Uncategorized": {},
"Uncategorized": {}
}
.minor-devices
each devices, groupKey in minorDevices
.row(class=groupKey)
- groupKey = "minorDevice" + groupKey
each value, key in devices
- key = groupKey + key
.col.s12.m6.l4
label(for=key)
input.with-gap(type="radio", name=groupKey, id=key, value=value)
span(i18n=key)
label(for="minorDevice" + groupKey + key)
input.with-gap(type="radio", name="minorDevice" + groupKey, id="minorDevice" + groupKey + key, value=value)
span(i18n="minorDevice." + groupKey + "." + key)
else
.col.s12
p(i18n="minorDeviceNone")
p(i18n="minorDevice.None")

Loading…
Cancel
Save