Centralize JS translations in skin.js.php with zmPrimeTranslations() for lazy priming#4804
Centralize JS translations in skin.js.php with zmPrimeTranslations() for lazy priming#4804
Conversation
… skin.js.php refs #4290 Agent-Logs-Url: https://github.com/ZoneMinder/zoneminder/sessions/f8ffacbf-358b-47f5-a732-afdd9e5854a8 Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ZoneMinder/zoneminder/sessions/f8ffacbf-358b-47f5-a732-afdd9e5854a8 Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
|
@copilot it would be nice if they would lazy load on use... and perhaps in each .js.php or even .js, we could call a function to prime it |
…er view refs #4290 Agent-Logs-Url: https://github.com/ZoneMinder/zoneminder/sessions/3607efe7-9a75-41ed-82f3-e4975e4c3654 Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ZoneMinder/zoneminder/sessions/3607efe7-9a75-41ed-82f3-e4975e4c3654 Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
Done in commit
const translate = {};
function zmPrimeTranslations(t) { Object.assign(translate, t); }
zmPrimeTranslations({
"Fullscreen": "...",
"EnableAlarms": "...",
// all common keys...
});Any view's zmPrimeTranslations({
"Show Zones": "<?php echo validJsStr(translate('Show Zones')) ?>",
"Hide Zones": "<?php echo validJsStr(translate('Hide Zones')) ?>",
});And the static The |
Each
*.js.phpview file independently defined atranslateJS object and common translated string constants, duplicating the same keys across multiple files with inconsistent escaping.Changes
skin.js.php— Defines an emptytranslateobject and azmPrimeTranslations(t)helper (callsObject.assign(translate, t)) that any file can call to register translations without overwriting the shared object. Primes all common translations in one place, including alarm-related keys (EnableAlarms,DisableAlarms,ForceAlarm,CancelForcedAlarm) thatMonitorStream.jsneeds across multiple views. Also defines common standalone string constants (deleteString,archivedString,unarchivedString,emailedString,yesString,noString,confirmDeleteEventsString), all usingvalidJsStr()uniformly.Removed from view files — Deleted the per-view
var translate = {...}definitions fromwatch.js.php,event.js.php, andzone.js.php. Removed duplicated standalone string constants fromevent.js.php,events.js.php,snapshot.js.php,snapshots.js.php,timeline.js.php,watch.js.php, andzone.js.php.Per-view priming pattern —
event.js.phpdemonstrates the pattern by callingzmPrimeTranslations({"Show Zones": "...", "Hide Zones": "..."})for its page-specific keys;event.jsaccesses them viatranslate["Show Zones"]/translate["Hide Zones"].MonitorStream.js— Updated 8 references from standalone variables (enableAlarmsStretc.) totranslate["EnableAlarms"]etc., sinceMonitorStream.jsis loaded across 5 different views.After — common translations registered once in
skin.js.php:Per-view additions in a view's
.js.php:The
Object.assignapproach makeszmPrimeTranslationsadditive and safe to call multiple times, laying the groundwork for future AJAX-loaded translations.