Debian Codegraph @

ts/l10n/l10n.ts

raw symbols SCIP
1 //
2 // Copyright 2017-21 Volker Sorge
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 /**
17 * @file Basic message file for l10n.
18 * @author [email protected] (Volker Sorge)
19 */
20
21 import { Enginescip-typescript npm . . common/`engine.ts`/Engine# } from '../common/engine.js'scip-typescript npm . . common/`engine.ts`/;
22 import { Variablesscip-typescript npm . . common/`variables.ts`/Variables# } from '../common/variables.js'scip-typescript npm . . common/`variables.ts`/;
23 import { Grammarscip-typescript npm . . rule_engine/`grammar.ts`/Grammar# } from '../rule_engine/grammar.js'scip-typescript npm . . rule_engine/`grammar.ts`/;
24
25 import { afscip-typescript npm . . l10n/locales/`locale_af.ts`/af(). } from './locales/locale_af.js'scip-typescript npm . . l10n/locales/`locale_af.ts`/;
26 import { cascip-typescript npm . . l10n/locales/`locale_ca.ts`/ca(). } from './locales/locale_ca.js'scip-typescript npm . . l10n/locales/`locale_ca.ts`/;
27 import { dascip-typescript npm . . l10n/locales/`locale_da.ts`/da(). } from './locales/locale_da.js'scip-typescript npm . . l10n/locales/`locale_da.ts`/;
28 import { descip-typescript npm . . l10n/locales/`locale_de.ts`/de(). } from './locales/locale_de.js'scip-typescript npm . . l10n/locales/`locale_de.ts`/;
29 import { enscip-typescript npm . . l10n/locales/`locale_en.ts`/en(). } from './locales/locale_en.js'scip-typescript npm . . l10n/locales/`locale_en.ts`/;
30 import { esscip-typescript npm . . l10n/locales/`locale_es.ts`/es(). } from './locales/locale_es.js'scip-typescript npm . . l10n/locales/`locale_es.ts`/;
31 import { euroscip-typescript npm . . l10n/locales/`locale_euro.ts`/euro(). } from './locales/locale_euro.js'scip-typescript npm . . l10n/locales/`locale_euro.ts`/;
32 import { frscip-typescript npm . . l10n/locales/`locale_fr.ts`/fr(). } from './locales/locale_fr.js'scip-typescript npm . . l10n/locales/`locale_fr.ts`/;
33 import { hiscip-typescript npm . . l10n/locales/`locale_hi.ts`/hi(). } from './locales/locale_hi.js'scip-typescript npm . . l10n/locales/`locale_hi.ts`/;
34 import { koscip-typescript npm . . l10n/locales/`locale_ko.ts`/ko(). } from './locales/locale_ko.js'scip-typescript npm . . l10n/locales/`locale_ko.ts`/;
35 import { itscip-typescript npm . . l10n/locales/`locale_it.ts`/it(). } from './locales/locale_it.js'scip-typescript npm . . l10n/locales/`locale_it.ts`/;
36 import { nbscip-typescript npm . . l10n/locales/`locale_nb.ts`/nb(). } from './locales/locale_nb.js'scip-typescript npm . . l10n/locales/`locale_nb.ts`/;
37 import { nemethscip-typescript npm . . l10n/locales/`locale_nemeth.ts`/nemeth(). } from './locales/locale_nemeth.js'scip-typescript npm . . l10n/locales/`locale_nemeth.ts`/;
38 import { nnscip-typescript npm . . l10n/locales/`locale_nn.ts`/nn(). } from './locales/locale_nn.js'scip-typescript npm . . l10n/locales/`locale_nn.ts`/;
39 import { svscip-typescript npm . . l10n/locales/`locale_sv.ts`/sv(). } from './locales/locale_sv.js'scip-typescript npm . . l10n/locales/`locale_sv.ts`/;
40 import { Localescip-typescript npm . . l10n/`locale.ts`/Locale#, LOCALEscip-typescript npm . . l10n/`locale.ts`/LOCALE. } from './locale.js'scip-typescript npm . . l10n/`locale.ts`/;
41
42 export const localesscip-typescript npm . . l10n/`l10n.ts`/locales.: { [key: string]: () => Localescip-typescript npm . . l10n/`locale.ts`/Locale# } = {
43 afscip-typescript npm . . l10n/`l10n.ts`/af0:: afscip-typescript npm . . l10n/locales/`locale_af.ts`/af().,
44 cascip-typescript npm . . l10n/`l10n.ts`/ca0:: cascip-typescript npm . . l10n/locales/`locale_ca.ts`/ca().,
45 dascip-typescript npm . . l10n/`l10n.ts`/da0:: dascip-typescript npm . . l10n/locales/`locale_da.ts`/da().,
46 descip-typescript npm . . l10n/`l10n.ts`/de0:: descip-typescript npm . . l10n/locales/`locale_de.ts`/de().,
47 enscip-typescript npm . . l10n/`l10n.ts`/en0:: enscip-typescript npm . . l10n/locales/`locale_en.ts`/en().,
48 esscip-typescript npm . . l10n/`l10n.ts`/es0:: esscip-typescript npm . . l10n/locales/`locale_es.ts`/es().,
49 euroscip-typescript npm . . l10n/`l10n.ts`/euro0:: euroscip-typescript npm . . l10n/locales/`locale_euro.ts`/euro().,
50 frscip-typescript npm . . l10n/`l10n.ts`/fr0:: frscip-typescript npm . . l10n/locales/`locale_fr.ts`/fr().,
51 hiscip-typescript npm . . l10n/`l10n.ts`/hi0:: hiscip-typescript npm . . l10n/locales/`locale_hi.ts`/hi().,
52 itscip-typescript npm . . l10n/`l10n.ts`/it0:: itscip-typescript npm . . l10n/locales/`locale_it.ts`/it().,
53 koscip-typescript npm . . l10n/`l10n.ts`/ko0:: koscip-typescript npm . . l10n/locales/`locale_ko.ts`/ko().,
54 nbscip-typescript npm . . l10n/`l10n.ts`/nb0:: nbscip-typescript npm . . l10n/locales/`locale_nb.ts`/nb().,
55 nnscip-typescript npm . . l10n/`l10n.ts`/nn0:: nnscip-typescript npm . . l10n/locales/`locale_nn.ts`/nn().,
56 svscip-typescript npm . . l10n/`l10n.ts`/sv0:: svscip-typescript npm . . l10n/locales/`locale_sv.ts`/sv().,
57 nemethscip-typescript npm . . l10n/`l10n.ts`/nemeth0:: nemethscip-typescript npm . . l10n/locales/`locale_nemeth.ts`/nemeth().
58 };
59
60 /**
61 * The basic method for setting the localized messages.
62 */
63 export function setLocalescip-typescript npm . . l10n/`l10n.ts`/setLocale().() {
64 const msgs = getLocalescip-typescript npm . . l10n/`l10n.ts`/getLocale().();
65 setSubisoscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msgs);
66 if (msgs) {
67 for (const key of Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.getOwnPropertyNamesscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#getOwnPropertyNames().(msgs)) {
68 // TODO (TS): See if this is really an object structure.
69 (LOCALEscip-typescript npm . . l10n/`locale.ts`/LOCALE. as any)[key] = (msgs as any)[key];
70 }
71 for (const [key, func] of Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.entriesscip-typescript npm typescript 5.9.3 lib/`lib.es2017.object.d.ts`/ObjectConstructor#entries().(msgs.CORRECTIONSscip-typescript npm . . l10n/`locale.ts`/Locale#CORRECTIONS.)) {
72 Grammarscip-typescript npm . . rule_engine/`grammar.ts`/Grammar#.getInstancescip-typescript npm . . rule_engine/`grammar.ts`/Grammar#getInstance().().setCorrectionscip-typescript npm . . rule_engine/`grammar.ts`/Grammar#setCorrection().(key, func);
73 }
74 // TODO (Speech Rules): This is temporary until locales are handled in a
75 // bespoke class.
76 // Locale.ALPHABETS.digitTrans.default = msgs.NUMBERS.numberToWords;
77 }
78 }
79
80 /**
81 * Sets the current subiso code if one exists.
82 *
83 * @param msg The current locale message structure.
84 */
85 function setSubisoscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msgscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msg): Localescip-typescript npm . . l10n/`locale.ts`/Locale#) {
86 const subiso = Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().subisoscip-typescript npm . . common/`engine.ts`/Engine#subiso.;
87 if (msgscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msg).SUBISOscip-typescript npm . . l10n/`locale.ts`/Locale#SUBISO..allscip-typescript npm . . l10n/`messages.ts`/SubIso#all..indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(subiso) === -1) {
88 Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().subisoscip-typescript npm . . common/`engine.ts`/Engine#subiso. = msgscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msg).SUBISOscip-typescript npm . . l10n/`locale.ts`/Locale#SUBISO..defaultscip-typescript npm . . l10n/`messages.ts`/SubIso#default.;
89 }
90 msgscip-typescript npm . . l10n/`l10n.ts`/setSubiso().(msg).SUBISOscip-typescript npm . . l10n/`locale.ts`/Locale#SUBISO..currentscip-typescript npm . . l10n/`messages.ts`/SubIso#current. = Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().subisoscip-typescript npm . . common/`engine.ts`/Engine#subiso.;
91 }
92
93 /**
94 * Gets locale message object. If the currently set locale does not exist, it
95 * defaults to English.
96 *
97 * @returns A message object.
98 */
99 function getLocalescip-typescript npm . . l10n/`l10n.ts`/getLocale().(): Localescip-typescript npm . . l10n/`locale.ts`/Locale# {
100 const locale = Variablesscip-typescript npm . . common/`variables.ts`/Variables#.ensureLocalescip-typescript npm . . common/`variables.ts`/Variables#ensureLocale().(
101 Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().localescip-typescript npm . . common/`engine.ts`/Engine#locale.,
102 Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().defaultLocalescip-typescript npm . . common/`engine.ts`/Engine#`<set>defaultLocale`().
103 );
104 Enginescip-typescript npm . . common/`engine.ts`/Engine#.getInstancescip-typescript npm . . common/`engine.ts`/Engine#getInstance().().localescip-typescript npm . . common/`engine.ts`/Engine#locale. = locale;
105 return localesscip-typescript npm . . l10n/`l10n.ts`/locales.[locale]();
106 }
107
108 /**
109 * Locale completion with loaded mathmaps.
110 *
111 * @param json The JSON of the locale map.
112 */
113 export function completeLocalescip-typescript npm . . l10n/`l10n.ts`/completeLocale().(jsonscip-typescript npm . . l10n/`l10n.ts`/completeLocale().(json): any) {
114 const locale = localesscip-typescript npm . . l10n/`l10n.ts`/locales.[jsonscip-typescript npm . . l10n/`l10n.ts`/completeLocale().(json).locale];
115 if (!locale) {
116 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..errorscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#error().('Locale ' + jsonscip-typescript npm . . l10n/`l10n.ts`/completeLocale().(json).locale + ' does not exist!');
117 return;
118 }
119 const kind = jsonscip-typescript npm . . l10n/`l10n.ts`/completeLocale().(json).kind.toUpperCase();
120 const messages = jsonscip-typescript npm . . l10n/`l10n.ts`/completeLocale().(json).messages;
121 if (!messages) return;
122 const loc = locale() as any;
123 for (const [key, value] of Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.entriesscip-typescript npm typescript 5.9.3 lib/`lib.es2017.object.d.ts`/ObjectConstructor#entries().(messages)) {
124 // TODO (TS): See if this is really an object structure.
125 loc[kind][key] = value;
126 }
127 }