mirror of
https://github.com/status-im/consul.git
synced 2025-01-12 14:55:02 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import I18nService, { formatOptionsSymbol } from 'consul-ui/services/i18n';
|
|
import ucfirst from 'consul-ui/utils/ucfirst';
|
|
|
|
import faker from 'faker';
|
|
|
|
// we currently use HTML in translations, so anything 'word-like' with these
|
|
// chars won't get translated
|
|
const translator = (cb) => (item) => !['<', '>', '='].includes(item) ? cb(item) : item;
|
|
|
|
export default class DebugI18nService extends I18nService {
|
|
formatMessage(value, formatOptions) {
|
|
const text = super.formatMessage(...arguments);
|
|
let locale = this.env.var('CONSUL_INTL_LOCALE');
|
|
if (locale) {
|
|
switch (this.env.var('CONSUL_INTL_LOCALE')) {
|
|
case '-':
|
|
return text
|
|
.split(' ')
|
|
.map(
|
|
translator((item) =>
|
|
item
|
|
.split('')
|
|
.map((item) => '-')
|
|
.join('')
|
|
)
|
|
)
|
|
.join(' ');
|
|
case 'la-fk':
|
|
locale = 'en';
|
|
// fallsthrough
|
|
default:
|
|
faker.locale = locale;
|
|
return text
|
|
.split(' ')
|
|
.map(
|
|
translator((item) => {
|
|
const word = faker.lorem.word();
|
|
return item.charAt(0) === item.charAt(0).toUpperCase() ? ucfirst(word) : word;
|
|
})
|
|
)
|
|
.join(' ');
|
|
}
|
|
}
|
|
return text;
|
|
}
|
|
[formatOptionsSymbol]() {
|
|
const formatOptions = super[formatOptionsSymbol](...arguments);
|
|
if (this.env.var('CONSUL_INTL_DEBUG')) {
|
|
return Object.fromEntries(
|
|
// skip ember-intl special props like htmlSafe and default
|
|
Object.entries(formatOptions).map(([key, value]) =>
|
|
!['htmlSafe', 'default'].includes(key) ? [key, `{${key}}`] : [key, value]
|
|
)
|
|
);
|
|
}
|
|
return formatOptions;
|
|
}
|
|
}
|