Files
harvester-ui-extension/pkg/harvester/utils/l10n-globals.js
T
marcelofukumoto 6e0e0237ef feat: use the SUSE Virtualization product name on Prime (#1202)
* feat: switch the product name with Rancher Prime

Use a [[Harvester]] token for the product name in the translations, so
Rancher 2.16 fills it from the l10n global that harvester-manager
registers: SUSE Virtualization on Rancher Prime, Harvester otherwise.

Rancher before 2.16 shows the tokens as written, so on those hosts (and
standalone) the extension resolves them to Harvester itself.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* feat: switch the standalone product name with the server flavor

Standalone has no Rancher Prime, so register the [[Harvester]] l10n
global from the server-flavor setting instead: SUSE Virtualization on
prime, Harvester otherwise.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: point the network policy banner to the documentation

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* feat: use the SUSE theme in standalone Prime

Standalone Prime kept the harvester brand and only overrode the primary
colour, so the rest of the palette and the fonts didn't match Rancher
Prime. Switch the ui-brand setting to suse in the store when the server
flavor is prime, which makes the shell load the SUSE theme.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: keep the SUSE theme after a brand setting change event

The watcher also reads the setting's value, so a change from the server
loaded into the same object switches the brand back to suse.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

---------

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
2026-10-26 17:28:50 +01:00

50 lines
1.6 KiB
JavaScript

import semver from 'semver';
// Rancher 2.16 resolves `[[name]]` tokens in translations from values registered as 'l10n-global'
export const L10N_GLOBALS_MIN_RANCHER_VERSION = '2.16.0';
// Name of the product name token, `[[Harvester]]`, and its value on Prime
export const PRODUCT_NAME_GLOBAL = 'Harvester';
export const PRIME_PRODUCT_NAME = 'SUSE Virtualization';
const TOKEN = /(\\?)\[\[([\w-]+)\]\]/g;
// Standalone has no Rancher Prime, the server-flavor setting decides instead
let standalonePrime = false;
export function setStandalonePrime(isPrime) {
standalonePrime = !!isPrime;
}
export function standaloneProductName() {
return standalonePrime ? PRIME_PRODUCT_NAME : PRODUCT_NAME_GLOBAL;
}
/**
* Whether the host Rancher resolves `[[name]]` tokens itself.
* A missing or unknown version counts as an older host.
*/
export function hostResolvesL10nGlobals(version) {
const v = semver.coerce(version);
return !!v && semver.gte(v, L10N_GLOBALS_MIN_RANCHER_VERSION);
}
/**
* Replace `[[name]]` tokens in every string of `translations`, in place, the same way Rancher 2.16 does:
* a known name gets its value, an unknown one falls back to the name and `\[[name]]` stays a literal `[[name]]`
*/
export function resolveL10nGlobals(translations, values = {}) {
Object.keys(translations || {}).forEach((key) => {
const value = translations[key];
if (typeof value === 'string') {
translations[key] = value.replace(TOKEN, (_, escaped, name) => (escaped ? `[[${ name }]]` : (values[name] ?? name)));
} else if (value && typeof value === 'object') {
resolveL10nGlobals(value, values);
}
});
return translations;
}