@vocab/core 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @vocab/core
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`09a698a`](https://github.com/seek-oss/vocab/commit/09a698af6aff86a851e4f829916b8f1f6beaca58) [#89](https://github.com/seek-oss/vocab/pull/89) Thanks [@mikebarkmin](https://github.com/mikebarkmin)! - Add exports to packages with multiple entry points. This fixes
8
+ `ERR_UNSUPPORTED_DIR_IMPORT` issues e.g. with NextJS or other setups, which
9
+ rely on the new node resolver when using ESM packages.
10
+
11
+ ## 1.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`87333d7`](https://github.com/seek-oss/vocab/commit/87333d79c4a883b07d7d8f2c272b16e2243c49bd) [#80](https://github.com/seek-oss/vocab/pull/80) Thanks [@askoufis](https://github.com/askoufis)! - Enable the creation of generated languages via the `generatedLanguages` config.
16
+ See [the docs] for more information and examples.
17
+
18
+ [the docs]: https://github.com/seek-oss/vocab#generated-languages
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`87333d7`](https://github.com/seek-oss/vocab/commit/87333d79c4a883b07d7d8f2c272b16e2243c49bd)]:
23
+ - @vocab/types@1.1.0
24
+
25
+ ## 1.0.4
26
+
27
+ ### Patch Changes
28
+
29
+ - [`206c0fa`](https://github.com/seek-oss/vocab/commit/206c0fa36b05f23da593ebed801197c523477af6) [#78](https://github.com/seek-oss/vocab/pull/78) Thanks [@askoufis](https://github.com/askoufis)! - Fix incorrect language hierarchy when an extended language extends another language
30
+
3
31
  ## 1.0.3
4
32
 
5
33
  ### Patch Changes
package/README.md CHANGED
@@ -184,6 +184,14 @@ Configuration can either be passed into the Node API directly or be gathered fro
184
184
  **vocab.config.js**
185
185
 
186
186
  ```js
187
+ function capitalize(element) {
188
+ return element.toUpperCase();
189
+ }
190
+
191
+ function pad(message) {
192
+ return '[' + message + ']';
193
+ }
194
+
187
195
  module.exports = {
188
196
  devLanguage: 'en',
189
197
  languages: [
@@ -192,11 +200,25 @@ module.exports = {
192
200
  { name: 'en-US', extends: 'en' },
193
201
  { name: 'fr-FR' }
194
202
  ],
203
+ /**
204
+ * An array of languages to generate based off translations for existing languages
205
+ * Default: []
206
+ */
207
+ generatedLanguages: [
208
+ {
209
+ name: 'generatedLangauge',
210
+ extends: 'en',
211
+ generator: {
212
+ transformElement: capitalize,
213
+ transformMessage: pad
214
+ }
215
+ }
216
+ ],
195
217
  /**
196
218
  * The root directory to compile and validate translations
197
219
  * Default: Current working directory
198
220
  */
199
- projectRoot: './example/';
221
+ projectRoot: './example/',
200
222
  /**
201
223
  * A custom suffix to name vocab translation directories
202
224
  * Default: '.vocab'
@@ -209,6 +231,131 @@ module.exports = {
209
231
  };
210
232
  ```
211
233
 
234
+ ## Generated languages
235
+
236
+ Vocab supports the creation of generated languages via the `generatedLanguages` config.
237
+
238
+ Generated languages are created by running a message `generator` over every translation message in an existing translation.
239
+ A `generator` may contain a `transformElement` function, a `transformMessage` function, or both.
240
+ Both of these functions accept a single string parameter and return a string.
241
+
242
+ `transformElement` is applied to string literal values contained within `MessageFormatElement`s.
243
+ A `MessageFormatElement` is an object representing a node in the AST of a compiled translation message.
244
+ Simply put, any text that would end up being translated by a translator, i.e. anything that is not part of the [ICU Message syntax], will be passed to `transformElement`.
245
+ An example of a use case for this function would be adding [diacritics] to every letter in order to stress your UI from a vertical line-height perspective.
246
+
247
+ `transformMessage` receives the entire translation message _after_ `transformElement` has been applied to its individual elements.
248
+ An example of a use case for this function would be adding padding text to the start/end of your messages in order to easily identify which text in your app has not been extracted into a `translations.json` file.
249
+
250
+ By default, a generated language's messages will be based off the `devLanguage`'s messages, but this can be overridden by providing an `extends` value that references another language.
251
+
252
+ **vocab.config.js**
253
+
254
+ ```js
255
+ function capitalize(message) {
256
+ return message.toUpperCase();
257
+ }
258
+
259
+ function pad(message) {
260
+ return '[' + message + ']';
261
+ }
262
+
263
+ module.exports = {
264
+ devLanguage: 'en',
265
+ languages: [{ name: 'en' }, { name: 'fr' }],
266
+ generatedLanguages: [
267
+ {
268
+ name: 'generatedLanguage',
269
+ extends: 'en',
270
+ generator: {
271
+ transformElement: capitalize,
272
+ transformMessage: pad
273
+ }
274
+ }
275
+ ]
276
+ };
277
+ ```
278
+
279
+ Generated languages are consumed the same way as regular languages.
280
+ Any Vocab API that accepts a `language` parameter will work with a generated language as well as a regular language.
281
+
282
+ **App.tsx**
283
+
284
+ ```tsx
285
+ const App = () => (
286
+ <VocabProvider language="generatedLanguage">
287
+ ...
288
+ </VocabProvider>
289
+ );
290
+ ```
291
+
292
+ [icu message syntax]: https://formatjs.io/docs/intl-messageformat/#message-syntax
293
+ [diacritics]: https://en.wikipedia.org/wiki/Diacritic
294
+
295
+ ## Pseudo-localization
296
+
297
+ The `@vocab/pseudo-localize` package exports low-level functions that can be used for pseudo-localization of translation messages.
298
+
299
+ ```ts
300
+ import {
301
+ extendVowels,
302
+ padString,
303
+ pseudoLocalize,
304
+ substituteCharacters
305
+ } from '@vocab/pseudo-localize';
306
+
307
+ const message = 'Hello';
308
+
309
+ // [Hello]
310
+ const paddedMessage = padString(message);
311
+
312
+ // Ḩẽƚƚö
313
+ const substitutedMessage = substituteCharacters(message);
314
+
315
+ // Heelloo
316
+ const extendedMessage = extendVowels(message);
317
+
318
+ // Extend the message and then substitute characters
319
+ // Ḩẽẽƚƚöö
320
+ const pseudoLocalizedMessage = pseudoLocalize(message);
321
+ ```
322
+
323
+ Pseudo-localization is a transformation that can be applied to a translation message.
324
+ Vocab's implementation of this transformation contains the following elements:
325
+
326
+ - _Start and end markers (`padString`):_ All strings are encapsulated in `[` and `]`. If a developer doesn’t see these characters they know the string has been clipped by an inflexible UI element.
327
+ - _Transformation of ASCII characters to extended character equivalents (`substituteCharacters`):_ Stresses the UI from a vertical line-height perspective, tests font and encoding support, and weeds out strings that haven’t been externalized correctly (they will not have the pseudo-localization applied to them).
328
+ - _Padding text (`extendVowels`):_ Simulates translation-induced expansion. Vocab's implementation of this involves repeating vowels (and `y`) to simulate a 40% expansion in the message's length.
329
+
330
+ This Netflix technology [blog post][blog post] inspired Vocab's implementation of this
331
+ functionality.
332
+
333
+ ### Generating a pseudo-localized language using Vocab
334
+
335
+ Vocab can generate a pseudo-localized language via the [`generatedLanguages` config][generated languages config], either via the webpack plugin or your `vocab.config.js` file.
336
+ `@vocab/pseudo-localize` exports a `generator` that can be used directly in your config.
337
+
338
+ **vocab.config.js**
339
+
340
+ ```js
341
+ const { generator } = require('@vocab/pseudo-localize');
342
+
343
+ module.exports = {
344
+ devLanguage: 'en',
345
+ languages: [{ name: 'en' }, { name: 'fr' }],
346
+ generatedLanguages: [
347
+ {
348
+ name: 'pseudo',
349
+ extends: 'en',
350
+ generator
351
+ }
352
+ ]
353
+ };
354
+ ```
355
+
356
+ [blog post]: https://netflixtechblog.com/pseudo-localization-netflix-12fff76fbcbe
357
+ [generated languages config]: #generated-languages
358
+
212
359
  ## Use without React
213
360
 
214
361
  If you need to use Vocab outside of React, you can access the returned Vocab file directly. You'll then be responsible for when to load translations and how to update on translation load.
@@ -0,0 +1,5 @@
1
+ import { MessageGenerator, TranslationsByKey } from '@vocab/types';
2
+ export declare function generateLanguageFromTranslations({ baseTranslations, generator, }: {
3
+ baseTranslations: TranslationsByKey<string>;
4
+ generator: MessageGenerator;
5
+ }): TranslationsByKey<string>;
@@ -1,9 +1,25 @@
1
- import { UserConfig, LoadedTranslation, LanguageTarget } from '@vocab/types';
1
+ import { TranslationsByKey, UserConfig, LoadedTranslation, LanguageTarget } from '@vocab/types';
2
2
  import { Fallback } from './utils';
3
3
  export declare function getUniqueKey(key: string, namespace: string): string;
4
- export declare function getLanguageHierarcy({ languages, }: {
4
+ export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
5
+ translation: TranslationsByKey;
6
+ devTranslation: TranslationsByKey;
7
+ }): TranslationsByKey<string>;
8
+ export declare function getLanguageHierarchy({ languages, }: {
5
9
  languages: Array<LanguageTarget>;
6
10
  }): Map<string, string[]>;
11
+ export declare function getFallbackLanguageOrder({ languages, languageName, devLanguage, fallbacks, }: {
12
+ languages: LanguageTarget[];
13
+ languageName: string;
14
+ devLanguage: string;
15
+ fallbacks: Fallback;
16
+ }): string[];
17
+ export declare function loadAltLanguageFile({ filePath, languageName, devTranslation, fallbacks, }: {
18
+ filePath: string;
19
+ languageName: string;
20
+ devTranslation: TranslationsByKey;
21
+ fallbacks: Fallback;
22
+ }, { devLanguage, languages }: UserConfig): TranslationsByKey;
7
23
  export declare function loadTranslation({ filePath, fallbacks, }: {
8
24
  filePath: string;
9
25
  fallbacks: Fallback;
@@ -1,3 +1,3 @@
1
1
  import { UserConfig, LoadedTranslation, LanguageName } from '@vocab/types';
2
- export declare function findMissingKeys(loadedTranslation: LoadedTranslation, devLanguageName: LanguageName, altLangauges: Array<LanguageName>): readonly [boolean, Record<string, string[]>];
2
+ export declare function findMissingKeys(loadedTranslation: LoadedTranslation, devLanguageName: LanguageName, altLanguages: Array<LanguageName>): readonly [boolean, Record<string, string[]>];
3
3
  export declare function validate(config: UserConfig): Promise<boolean>;
@@ -10,6 +10,8 @@ var chokidar = require('chokidar');
10
10
  var chalk = require('chalk');
11
11
  var debug = require('debug');
12
12
  var glob = require('fast-glob');
13
+ var IntlMessageFormat = require('intl-messageformat');
14
+ var printer = require('@formatjs/icu-messageformat-parser/printer');
13
15
  var findUp = require('find-up');
14
16
  var Validator = require('fastest-validator');
15
17
 
@@ -21,6 +23,7 @@ var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
21
23
  var chalk__default = /*#__PURE__*/_interopDefault(chalk);
22
24
  var debug__default = /*#__PURE__*/_interopDefault(debug);
23
25
  var glob__default = /*#__PURE__*/_interopDefault(glob);
26
+ var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
24
27
  var findUp__default = /*#__PURE__*/_interopDefault(findUp);
25
28
  var Validator__default = /*#__PURE__*/_interopDefault(Validator);
26
29
 
@@ -108,11 +111,78 @@ function getTranslationMessages(translations) {
108
111
  return mapValues(translations, v => v.message);
109
112
  }
110
113
 
114
+ function generateLanguageFromTranslations({
115
+ baseTranslations,
116
+ generator
117
+ }) {
118
+ if (!generator.transformElement && !generator.transformMessage) {
119
+ return baseTranslations;
120
+ }
121
+
122
+ const translationKeys = Object.keys(baseTranslations);
123
+ const generatedTranslations = {};
124
+
125
+ for (const translationKey of translationKeys) {
126
+ const translation = baseTranslations[translationKey];
127
+ let transformedMessage = translation.message;
128
+
129
+ if (generator.transformElement) {
130
+ const messageAst = new IntlMessageFormat__default['default'](translation.message).getAst();
131
+ const transformedAst = messageAst.map(transformMessageFormatElement(generator.transformElement));
132
+ transformedMessage = printer.printAST(transformedAst);
133
+ }
134
+
135
+ if (generator.transformMessage) {
136
+ transformedMessage = generator.transformMessage(transformedMessage);
137
+ }
138
+
139
+ generatedTranslations[translationKey] = {
140
+ message: transformedMessage
141
+ };
142
+ }
143
+
144
+ return generatedTranslations;
145
+ }
146
+
147
+ function transformMessageFormatElement(transformElement) {
148
+ return messageFormatElement => {
149
+ const transformedMessageFormatElement = { ...messageFormatElement
150
+ };
151
+
152
+ switch (transformedMessageFormatElement.type) {
153
+ case icuMessageformatParser.TYPE.literal:
154
+ const transformedValue = transformElement(transformedMessageFormatElement.value);
155
+ transformedMessageFormatElement.value = transformedValue;
156
+ break;
157
+
158
+ case icuMessageformatParser.TYPE.select:
159
+ case icuMessageformatParser.TYPE.plural:
160
+ const transformedOptions = { ...transformedMessageFormatElement.options
161
+ };
162
+
163
+ for (const key of Object.keys(transformedOptions)) {
164
+ transformedOptions[key].value = transformedOptions[key].value.map(transformMessageFormatElement(transformElement));
165
+ }
166
+
167
+ break;
168
+
169
+ case icuMessageformatParser.TYPE.tag:
170
+ const transformedChildren = transformedMessageFormatElement.children.map(transformMessageFormatElement(transformElement));
171
+ transformedMessageFormatElement.children = transformedChildren;
172
+ break;
173
+ }
174
+
175
+ return transformedMessageFormatElement;
176
+ };
177
+ }
178
+
111
179
  function getUniqueKey(key, namespace) {
112
180
  return `${key}.${namespace}`;
113
181
  }
114
-
115
- function mergeWithDevLanguage(translation, devTranslation) {
182
+ function mergeWithDevLanguageTranslation({
183
+ translation,
184
+ devTranslation
185
+ }) {
116
186
  // Only use keys from the dev translation
117
187
  const keys = Object.keys(devTranslation);
118
188
  const newLanguage = {};
@@ -143,7 +213,7 @@ function getLanguageFallbacks({
143
213
  return languageFallbackMap;
144
214
  }
145
215
 
146
- function getLanguageHierarcy({
216
+ function getLanguageHierarchy({
147
217
  languages
148
218
  }) {
149
219
  const hierarchyMap = new Map();
@@ -152,19 +222,45 @@ function getLanguageHierarcy({
152
222
  });
153
223
 
154
224
  for (const lang of languages) {
155
- const langHierachy = [];
225
+ const langHierarchy = [];
156
226
  let currLang = lang.extends;
157
227
 
158
228
  while (currLang) {
159
- langHierachy.push(currLang);
229
+ langHierarchy.push(currLang);
160
230
  currLang = fallbacks.get(currLang);
161
231
  }
162
232
 
163
- hierarchyMap.set(lang.name, langHierachy);
233
+ hierarchyMap.set(lang.name, langHierarchy);
164
234
  }
165
235
 
166
236
  return hierarchyMap;
167
237
  }
238
+ function getFallbackLanguageOrder({
239
+ languages,
240
+ languageName,
241
+ devLanguage,
242
+ fallbacks
243
+ }) {
244
+ const languageHierarchy = getLanguageHierarchy({
245
+ languages
246
+ }).get(languageName);
247
+
248
+ if (!languageHierarchy) {
249
+ throw new Error(`Missing language hierarchy for ${languageName}`);
250
+ }
251
+
252
+ const fallbackLanguageOrder = [languageName];
253
+
254
+ if (fallbacks !== 'none') {
255
+ fallbackLanguageOrder.unshift(...languageHierarchy.reverse());
256
+
257
+ if (fallbacks === 'all' && fallbackLanguageOrder[0] !== devLanguage) {
258
+ fallbackLanguageOrder.unshift(devLanguage);
259
+ }
260
+ }
261
+
262
+ return fallbackLanguageOrder;
263
+ }
168
264
 
169
265
  function getNamespaceByFilePath(relativePath, {
170
266
  translationsDirectorySuffix = defaultTranslationDirSuffix
@@ -208,17 +304,17 @@ function getTranslationsFromFile(translations, {
208
304
 
209
305
  for (const [translationKey, translation] of Object.entries(keys)) {
210
306
  if (typeof translation === 'string') {
211
- printValidationError(`Found string for a translation "${translationKey}" in ${filePath}. Translation must be an object of the format {mesage: string}.`);
307
+ printValidationError(`Found string for a translation "${translationKey}" in ${filePath}. Translation must be an object of the format {message: string}.`);
212
308
  continue;
213
309
  }
214
310
 
215
311
  if (!translation) {
216
- printValidationError(`Found empty translation "${translationKey}" in ${filePath}. Translation must be an object of the format {mesage: string}.`);
312
+ printValidationError(`Found empty translation "${translationKey}" in ${filePath}. Translation must be an object of the format {message: string}.`);
217
313
  continue;
218
314
  }
219
315
 
220
316
  if (!translation.message || typeof translation.message !== 'string') {
221
- printValidationError(`No message found for translation "${translationKey}" in ${filePath}. Translation must be an object of the format {mesage: string}.`);
317
+ printValidationError(`No message found for translation "${translationKey}" in ${filePath}. Translation must be an object of the format {message: string}.`);
222
318
  continue;
223
319
  }
224
320
 
@@ -240,54 +336,44 @@ function loadAltLanguageFile({
240
336
  devLanguage,
241
337
  languages
242
338
  }) {
243
- const result = {};
244
- const languageHierarchy = getLanguageHierarcy({
245
- languages
246
- }).get(languageName);
247
-
248
- if (!languageHierarchy) {
249
- throw new Error(`Missing language hierarchy for ${languageName}`);
250
- }
251
-
252
- const fallbackLanguages = [languageName];
253
-
254
- if (fallbacks !== 'none') {
255
- fallbackLanguages.unshift(...languageHierarchy);
256
-
257
- if (fallbacks === 'all' && fallbackLanguages[0] !== devLanguage) {
258
- fallbackLanguages.unshift(devLanguage);
259
- }
260
- }
261
-
262
- trace(`Loading alt language file with precendence: ${fallbackLanguages.slice().reverse().join(' -> ')}`);
339
+ const altLanguageTranslation = {};
340
+ const fallbackLanguageOrder = getFallbackLanguageOrder({
341
+ languages,
342
+ languageName,
343
+ devLanguage,
344
+ fallbacks
345
+ });
346
+ trace(`Loading alt language file with precedence: ${fallbackLanguageOrder.slice().reverse().join(' -> ')}`);
263
347
 
264
- for (const fallbackLang of fallbackLanguages) {
265
- if (fallbackLang !== devLanguage) {
348
+ for (const fallbackLanguage of fallbackLanguageOrder) {
349
+ if (fallbackLanguage !== devLanguage) {
266
350
  try {
267
- const altFilePath = getAltLanguageFilePath(filePath, fallbackLang);
351
+ const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
268
352
  delete require.cache[altFilePath];
269
353
 
270
354
  const translationFile = require(altFilePath);
271
355
 
272
356
  const {
273
- keys
357
+ keys: fallbackLanguageTranslation
274
358
  } = getTranslationsFromFile(translationFile, {
275
359
  filePath: altFilePath,
276
360
  isAltLanguage: true
277
361
  });
278
- Object.assign(result, mergeWithDevLanguage(keys, devTranslation));
362
+ Object.assign(altLanguageTranslation, mergeWithDevLanguageTranslation({
363
+ translation: fallbackLanguageTranslation,
364
+ devTranslation
365
+ }));
279
366
  } catch (e) {
280
- trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLang)}
367
+ trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
281
368
  `);
282
369
  }
283
370
  } else {
284
- Object.assign(result, devTranslation);
371
+ Object.assign(altLanguageTranslation, devTranslation);
285
372
  }
286
373
  }
287
374
 
288
- return result;
375
+ return altLanguageTranslation;
289
376
  }
290
-
291
377
  function loadTranslation({
292
378
  filePath,
293
379
  fallbacks
@@ -320,6 +406,19 @@ function loadTranslation({
320
406
  }, userConfig);
321
407
  }
322
408
 
409
+ for (const generatedLanguage of userConfig.generatedLanguages || []) {
410
+ const {
411
+ name: generatedLanguageName,
412
+ generator
413
+ } = generatedLanguage;
414
+ const baseLanguage = generatedLanguage.extends || userConfig.devLanguage;
415
+ const baseTranslations = languageSet[baseLanguage];
416
+ languageSet[generatedLanguageName] = generateLanguageFromTranslations({
417
+ baseTranslations,
418
+ generator
419
+ });
420
+ }
421
+
323
422
  return {
324
423
  filePath,
325
424
  keys: Object.keys(devTranslation),
@@ -603,7 +702,7 @@ async function writeIfChanged(filepath, contents) {
603
702
  }
604
703
 
605
704
  /* eslint-disable no-console */
606
- function findMissingKeys(loadedTranslation, devLanguageName, altLangauges) {
705
+ function findMissingKeys(loadedTranslation, devLanguageName, altLanguages) {
607
706
  const devLanguage = loadedTranslation.languages[devLanguageName];
608
707
 
609
708
  if (!devLanguage) {
@@ -615,7 +714,7 @@ function findMissingKeys(loadedTranslation, devLanguageName, altLangauges) {
615
714
  const requiredKeys = Object.keys(devLanguage);
616
715
 
617
716
  if (requiredKeys.length > 0) {
618
- for (const altLanguageName of altLangauges) {
717
+ for (const altLanguageName of altLanguages) {
619
718
  var _loadedTranslation$la;
620
719
 
621
720
  const altLanguage = (_loadedTranslation$la = loadedTranslation.languages[altLanguageName]) !== null && _loadedTranslation$la !== void 0 ? _loadedTranslation$la : {};
@@ -691,6 +790,35 @@ const schema = {
691
790
  }
692
791
  }
693
792
  },
793
+ generatedLanguages: {
794
+ type: 'array',
795
+ items: {
796
+ type: 'object',
797
+ props: {
798
+ name: {
799
+ type: 'string'
800
+ },
801
+ extends: {
802
+ type: 'string',
803
+ optional: true
804
+ },
805
+ generator: {
806
+ type: 'object',
807
+ props: {
808
+ transformElement: {
809
+ type: 'function',
810
+ optional: true
811
+ },
812
+ transformMessage: {
813
+ type: 'function',
814
+ optional: true
815
+ }
816
+ }
817
+ }
818
+ }
819
+ },
820
+ optional: true
821
+ },
694
822
  translationsDirectorySuffix: {
695
823
  type: 'string',
696
824
  optional: true
@@ -728,13 +856,12 @@ function validateConfig(c) {
728
856
 
729
857
  return v.message;
730
858
  }).join(' \n'));
731
- } // Dev Language should exist in languages
732
-
859
+ }
733
860
 
734
- const languageStrings = c.languages.map(v => v.name);
861
+ const languageStrings = c.languages.map(v => v.name); // Dev Language should exist in languages
735
862
 
736
863
  if (!languageStrings.includes(c.devLanguage)) {
737
- throw new ValidationError('InvalidDevLanguage', `InvalidDevLanguage: The dev language "${chalk__default['default'].bold.cyan(c.devLanguage)}" was not found in languages ${languageStrings.join(', ')}.`);
864
+ throw new ValidationError('InvalidDevLanguage', `The dev language "${chalk__default['default'].bold.cyan(c.devLanguage)}" was not found in languages ${languageStrings.join(', ')}.`);
738
865
  }
739
866
 
740
867
  const foundLanguages = [];
@@ -752,6 +879,26 @@ function validateConfig(c) {
752
879
  }
753
880
  }
754
881
 
882
+ const foundGeneratedLanguages = [];
883
+
884
+ for (const generatedLang of c.generatedLanguages || []) {
885
+ // Generated languages must only exist once
886
+ if (foundGeneratedLanguages.includes(generatedLang.name)) {
887
+ throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${chalk__default['default'].bold.cyan(generatedLang.name)}" was defined multiple times.`);
888
+ }
889
+
890
+ foundGeneratedLanguages.push(generatedLang.name); // Generated language names must not conflict with language names
891
+
892
+ if (languageStrings.includes(generatedLang.name)) {
893
+ throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${chalk__default['default'].bold.cyan(generatedLang.name)}" is already defined as a language.`);
894
+ } // Any extends must be in languages
895
+
896
+
897
+ if (generatedLang.extends && !languageStrings.includes(generatedLang.extends)) {
898
+ throw new ValidationError('InvalidExtends', `The generated language "${chalk__default['default'].bold.cyan(generatedLang.name)}"'s extends of ${chalk__default['default'].bold.cyan(generatedLang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
899
+ }
900
+ }
901
+
755
902
  trace('Configuration file is valid');
756
903
  return true;
757
904
  }