diff --git a/src/BuildEngineFactory.ts b/src/BuildEngineFactory.ts index 78a2de2f0f..cd77590060 100644 --- a/src/BuildEngineFactory.ts +++ b/src/BuildEngineFactory.ts @@ -1,4 +1,4 @@ -import {LazilyTransformingAstService} from './' +import {LazilyTransformingAstService} from './LazilyTransformingAstService' import {CellContentParser} from './CellContentParser' import {Exporter} from './CellValue' import {buildColumnSearchStrategy, ColumnSearchStrategy} from './ColumnSearch/ColumnSearchStrategy' @@ -102,7 +102,7 @@ export class BuildEngineFactory { public static buildFromSheet(sheet: Sheet, configInput?: Partial): EngineState { const config = new Config(configInput) - const newsheetprefix = config.translationPackage.getUITranslation(UIElement.NEW_SHEET_PREFIX)! + '1' + const newsheetprefix = config.translationPackage.getUITranslation(UIElement.NEW_SHEET_PREFIX) + '1' return this.buildEngine(config, {[newsheetprefix]: sheet}) } diff --git a/src/CellValue.ts b/src/CellValue.ts index 2c0cd6c61f..f1a00f98cd 100644 --- a/src/CellValue.ts +++ b/src/CellValue.ts @@ -87,7 +87,7 @@ export class Exporter { } private detailedError(error: CellError): DetailedCellError { - return new DetailedCellError(error, this.config.getErrorTranslationFor(error.type)) + return new DetailedCellError(error, this.config.translationPackage.getErrorTranslation(error.type)) } private cellValueRounding(value: number): number { diff --git a/src/Config.ts b/src/Config.ts index 541d3bb598..eb9cf49977 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -2,7 +2,7 @@ import {ErrorType} from './Cell' import {defaultParseToDate, instanceOfSimpleDate, SimpleDate} from './DateHelper' import {ExpectedOneOfValues, ExpectedValueOfType} from './errors' import {AlwaysDense, ChooseAddressMapping} from './DependencyGraph/AddressMapping/ChooseAddressMappingPolicy' -import {HyperFormula} from './index' +import {HyperFormula} from './HyperFormula' import {defaultPrintDate} from './format/format' import {TranslationPackage} from './i18n' import {AbsPlugin} from './interpreter/plugin/AbsPlugin' @@ -526,22 +526,6 @@ export class Config implements ConfigParams, ParserConfig { return new Config(mergedConfig) } - public getFunctionTranslationFor = (functionTranslationKey: string): string => { - const translation = this.translationPackage.getFunctionTranslation(functionTranslationKey) - if(translation === undefined) { - throw new Error('No translation for function.') - } - return translation - } - - public getErrorTranslationFor = (functionTranslationKey: ErrorType): string => { - const translation = this.translationPackage.getErrorTranslation(functionTranslationKey) - if(translation === undefined) { - throw new Error('No translation for error.') - } - return translation - } - // eslint-disable-next-line @typescript-eslint/no-explicit-any public allFunctionPlugins(): any[] { return [...Config.defaultPlugins, ...this.functionPlugins] @@ -554,7 +538,7 @@ export class Config implements ConfigParams, ParserConfig { for (const functionKey in plugin.implementedFunctions) { const pluginFunctionData = plugin.implementedFunctions[functionKey] if (pluginFunctionData.isVolatile) { - volatileFunctions.add(this.getFunctionTranslationFor(pluginFunctionData.translationKey)) + volatileFunctions.add(this.translationPackage.getFunctionTranslation(pluginFunctionData.translationKey)) } } } @@ -569,7 +553,7 @@ export class Config implements ConfigParams, ParserConfig { for (const functionKey in plugin.implementedFunctions) { const pluginFunctionData = plugin.implementedFunctions[functionKey] if (pluginFunctionData.isDependentOnSheetStructureChange) { - structuralChangeFunctions.add(this.getFunctionTranslationFor(pluginFunctionData.translationKey)) + structuralChangeFunctions.add(this.translationPackage.getFunctionTranslation(pluginFunctionData.translationKey)) } } } @@ -583,7 +567,7 @@ export class Config implements ConfigParams, ParserConfig { for (const functionKey in plugin.implementedFunctions) { const pluginFunctionData = plugin.implementedFunctions[functionKey] if (pluginFunctionData.doesNotNeedArgumentsToBeComputed) { - functionsWhichDoesNotNeedArgumentsToBeComputed.add(this.getFunctionTranslationFor(pluginFunctionData.translationKey)) + functionsWhichDoesNotNeedArgumentsToBeComputed.add(this.translationPackage.getFunctionTranslation(pluginFunctionData.translationKey)) } } } diff --git a/src/DependencyGraph/SheetMapping.ts b/src/DependencyGraph/SheetMapping.ts index 3085c68912..e15a2488bb 100644 --- a/src/DependencyGraph/SheetMapping.ts +++ b/src/DependencyGraph/SheetMapping.ts @@ -26,11 +26,7 @@ export class SheetMapping { private lastSheetId = -1 constructor(private languages: TranslationPackage) { - const sheetNamePrefix = languages.getUITranslation(UIElement.NEW_SHEET_PREFIX) - if(sheetNamePrefix===undefined) { - throw new Error('No translation for sheet prefix.') - } - this.sheetNamePrefix = sheetNamePrefix + this.sheetNamePrefix = languages.getUITranslation(UIElement.NEW_SHEET_PREFIX) } public addSheet(newSheetDisplayName: string = `${this.sheetNamePrefix}${this.lastSheetId + 2}`): number { diff --git a/src/HyperFormula.ts b/src/HyperFormula.ts index 8cd90ac179..68af984c01 100644 --- a/src/HyperFormula.ts +++ b/src/HyperFormula.ts @@ -1,4 +1,4 @@ -import {AbsoluteCellRange} from './AbsoluteCellRange' +import { AbsoluteCellRange } from './AbsoluteCellRange' import {CellType, CellValueType, getCellType, getCellValueType, NoErrorCellValue, SimpleCellAddress} from './Cell' import {CellContent, CellContentParser, RawCellContent} from './CellContentParser' import {CellValue, ExportedChange, Exporter} from './CellValue' @@ -218,6 +218,10 @@ export class HyperFormula implements TypedEmitter { } } + /** + * Unregisters language that is registered under given code string. + * @param {string} code - code string of the translation package + */ public static unregisterLanguage(code: string): void { if(this.registeredLanguages.has(code)) { this.registeredLanguages.delete(code) @@ -226,10 +230,6 @@ export class HyperFormula implements TypedEmitter { } } - public static unregisterAllLanguages(): void { - this.registeredLanguages = new Map() - } - /** * Returns all registered languages codes. */ @@ -1657,3 +1657,4 @@ export class HyperFormula implements TypedEmitter { } } } + diff --git a/src/Serialization.ts b/src/Serialization.ts index cb4d547bac..4fc2cc850c 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -36,7 +36,7 @@ export class Serialization { } else { const value: CellValue = this.getCellValue(address) if(value instanceof DetailedCellError) { - return this.config.getErrorTranslationFor(value.error.type) + return this.config.translationPackage.getErrorTranslation(value.error.type) } else { return value } diff --git a/src/errors.ts b/src/errors.ts index 658886b783..29eddf8e6f 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -161,3 +161,14 @@ export class EvaluationSuspendedError extends Error { super('Computations are suspended') } } + +/** + * Error thrown when translation is missing in translation package. + * + * TODO + */ +export class MissingTranslationError extends Error { + constructor(key: string) { + super(`Translation for ${key} is missing in the translation package you're using.`) + } +} diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index 583b85dbbe..1166e19963 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -1,5 +1,5 @@ import {ErrorType} from '../Cell' -import {Maybe} from '../Maybe' +import {MissingTranslationError} from '../errors' import {ErrorTranslationSet, TranslationSet, UIElement, UITranslationSet} from './index' export interface RawTranslationPackage { @@ -36,27 +36,46 @@ export class TranslationPackage { }, {} as Record) } - public getFunctionTranslation(key: string): Maybe { - return this.functions[key] + public isFunctionTranslated(key: string): boolean { + return this.functions[key] !== undefined } - public getErrorTranslation(key: ErrorType): Maybe { - return this.errors[key] + + public getFunctionTranslation(key: string): string { + const val = this.functions[key] + if(val === undefined) { + throw new MissingTranslationError(`functions.${key}`) + } else { + return val + } } - public getUITranslation(key: UIElement): Maybe { - return this.ui[key] + public getErrorTranslation(key: ErrorType): string { + const val = this.errors[key] + if(val === undefined) { + throw new MissingTranslationError(`errors.${key}`) + } else { + return val + } + } + public getUITranslation(key: UIElement): string { + const val = this.ui[key] + if(val === undefined) { + throw new MissingTranslationError(`ui.${key}`) + } else { + return val + } } private checkUI(): void { - for(const err of Object.values(UIElement)){ - if(! (err in this.ui)){ - throw new Error('No translation for error.') + for(const key of Object.values(UIElement)){ + if(! (key in this.ui)){ + throw new MissingTranslationError(`ui.${key}`) } } } private checkErrors(): void { - for(const err of Object.values(ErrorType)){ - if(! (err in this.errors)){ - throw new Error('No translation for error.') + for(const key of Object.values(ErrorType)){ + if(! (key in this.errors)){ + throw new MissingTranslationError(`errors.${key}`) } } } diff --git a/src/index.ts b/src/index.ts index b4ef0b68cb..18bdcb7dd5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { CellError, EmptyValue } from './Cell' +import { CellError, EmptyValue, ErrorType } from './Cell' import { CellValue, DetailedCellError, ExportedCellChange, ExportedNamedExpressionChange } from './CellValue' import { InvalidAddressError, @@ -10,7 +10,8 @@ import { } from './errors' import {Sheets} from './GraphBuilder' import {HyperFormula} from './HyperFormula' -import {enGB} from './i18n' +import {Config} from './Config' +import {languages} from './i18n' import {LazilyTransformingAstService} from './LazilyTransformingAstService' class HyperFormulaNS extends HyperFormula { @@ -24,9 +25,13 @@ class HyperFormulaNS extends HyperFormula { public static ExportedCellChange = ExportedCellChange public static ExportedNamedExpressionChange = ExportedNamedExpressionChange public static EvaluationSuspendedError = EvaluationSuspendedError + public static ErrorType = ErrorType + public static CellError = CellError + public static InvalidArgumentsError = InvalidArgumentsError } -HyperFormula.registerLanguage('enGB', enGB) +const defaultLanguage = Config.defaultConfig.language +HyperFormula.registerLanguage(defaultLanguage, languages[defaultLanguage]) export default HyperFormulaNS @@ -46,4 +51,5 @@ export { ExportedNamedExpressionChange, NoOperationToUndo, EvaluationSuspendedError, + ErrorType } diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index b965369c93..b26b47d818 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -171,8 +171,7 @@ export class Interpreter { } case AstNodeType.FUNCTION_CALL: { const pluginEntry = this.pluginCache.get(ast.procedureName) - const procedureName = this.config.translationPackage.getFunctionTranslation(ast.procedureName) - if (pluginEntry && procedureName!==undefined) { + if (pluginEntry && this.config.translationPackage.isFunctionTranslated(ast.procedureName)) { const [pluginInstance, pluginFunction] = pluginEntry return pluginInstance[pluginFunction](ast, formulaAddress) } else { diff --git a/src/parser/LexerConfig.ts b/src/parser/LexerConfig.ts index d7c9ac11eb..921b1d660e 100644 --- a/src/parser/LexerConfig.ts +++ b/src/parser/LexerConfig.ts @@ -88,7 +88,7 @@ export interface ILexerConfig { } export const buildLexerConfig = (config: ParserConfig): ILexerConfig => { - const offsetProcedureNameLiteral = config.getFunctionTranslationFor('OFFSET') + const offsetProcedureNameLiteral = config.translationPackage.getFunctionTranslation('OFFSET') const errorMapping = config.errorMapping const functionMapping = config.translationPackage.buildFunctionMapping() diff --git a/src/parser/ParserConfig.ts b/src/parser/ParserConfig.ts index 99562adf61..a6c6575853 100644 --- a/src/parser/ParserConfig.ts +++ b/src/parser/ParserConfig.ts @@ -9,6 +9,4 @@ export interface ParserConfig { volatileFunctions(): Set, structuralChangeFunctions(): Set, functionsWhichDoesNotNeedArgumentsToBeComputed(): Set, - getErrorTranslationFor(errorType: ErrorType): string, - getFunctionTranslationFor(functionName: string): string, } diff --git a/src/parser/ParserWithCaching.ts b/src/parser/ParserWithCaching.ts index e7fd967cd3..74c7ff9887 100644 --- a/src/parser/ParserWithCaching.ts +++ b/src/parser/ParserWithCaching.ts @@ -188,7 +188,7 @@ export class ParserWithCaching { return this.computeHashOfAstNode(ast.value) + imageWithWhitespace('%', ast.leadingWhitespace) } case AstNodeType.ERROR: { - const image = this.config.getErrorTranslationFor( + const image = this.config.translationPackage.getErrorTranslation( ast.error ? ast.error.type : ErrorType.ERROR ) return imageWithWhitespace(image, ast.leadingWhitespace) diff --git a/src/parser/Unparser.ts b/src/parser/Unparser.ts index 15a5b76b76..6d3803183a 100644 --- a/src/parser/Unparser.ts +++ b/src/parser/Unparser.ts @@ -36,7 +36,9 @@ export class Unparser { } case AstNodeType.FUNCTION_CALL: { const args = ast.args.map((arg) => this.unparseAst(arg, address)).join(this.config.functionArgSeparator) - const procedureName = this.config.translationPackage.getFunctionTranslation(ast.procedureName) ?? ast.procedureName + const procedureName = this.config.translationPackage.isFunctionTranslated(ast.procedureName) ? + this.config.translationPackage.getFunctionTranslation(ast.procedureName) : + ast.procedureName const rightPart = procedureName + '(' + args + imageWithWhitespace(')', ast.internalWhitespace) return imageWithWhitespace(rightPart, ast.leadingWhitespace) } @@ -66,7 +68,7 @@ export class Unparser { return this.unparseAst(ast.value, address) + imageWithWhitespace('%', ast.leadingWhitespace) } case AstNodeType.ERROR: { - const image = this.config.getErrorTranslationFor( + const image = this.config.translationPackage.getErrorTranslation( ast.error ? ast.error.type : ErrorType.ERROR ) return imageWithWhitespace(image, ast.leadingWhitespace) diff --git a/test/config.spec.ts b/test/config.spec.ts index 40633bff24..ac76e9bbe5 100644 --- a/test/config.spec.ts +++ b/test/config.spec.ts @@ -1,10 +1,11 @@ import {EmptyValue, HyperFormula} from '../src' import {Config} from '../src/Config' import {enGB, plPL} from '../src/i18n' +import {unregisterAllLanguages} from './testUtils' describe('Config', () => { beforeEach(() => { - HyperFormula.unregisterAllLanguages() + unregisterAllLanguages() HyperFormula.registerLanguage('plPL', plPL) HyperFormula.registerLanguage('enGB', enGB) }) @@ -30,7 +31,7 @@ describe('Config', () => { it('can translate functions', () => { const config = new Config({ language: 'plPL' }) - expect(config.getFunctionTranslationFor('SUM')).toEqual('SUMA') + expect(config.translationPackage.getFunctionTranslation('SUM')).toEqual('SUMA') }) it( 'validation: boolean params', () => { diff --git a/test/date.spec.ts b/test/date.spec.ts index 39bd4508d1..9494b95a81 100644 --- a/test/date.spec.ts +++ b/test/date.spec.ts @@ -2,6 +2,7 @@ import {Config} from '../src/Config' import {DateHelper, SimpleDate} from '../src/DateHelper' import moment from 'moment' import {Maybe} from '../src/Maybe' +import './testConfig' describe('Date helpers', () => { it('#dateToNumber should return number representation of a date', () => { diff --git a/test/extending-plugins.spec.ts b/test/extending-plugins.spec.ts index d7d17adf52..7bdc971273 100644 --- a/test/extending-plugins.spec.ts +++ b/test/extending-plugins.spec.ts @@ -1,5 +1,5 @@ import {HyperFormula} from '../src' -import {ErrorType} from '../src/Cell' +import {ErrorType} from '../src' import {FunctionPlugin, PluginFunctionType} from '../src/interpreter/plugin/FunctionPlugin' import './testConfig.ts' import {adr, detailedError} from './testUtils' @@ -26,7 +26,7 @@ describe('Plugins', () => { expect(engine.getCellValue(adr('A1'))).toBe(42) }) - it('cleanup - broken', () => { //TODO: loading plugin automatically adds translation to plugin cache + it('cleanup - broken', () => { const engine = HyperFormula.buildFromArray([ ['=foo()'], ], {functionPlugins: [FooPlugin]}) diff --git a/test/format/format-interpreter.spec.ts b/test/format/format-interpreter.spec.ts index 57c2d3556c..029acb8fec 100644 --- a/test/format/format-interpreter.spec.ts +++ b/test/format/format-interpreter.spec.ts @@ -1,6 +1,7 @@ import {Config} from '../../src/Config' import {DateHelper} from '../../src/DateHelper' import {format} from '../../src/format/format' +import '../testConfig' describe('FormatInterpreter', () => { const config = new Config() diff --git a/test/interpreter/scalar.spec.ts b/test/interpreter/scalar.spec.ts index e90962f90c..2c3cb1c8ca 100644 --- a/test/interpreter/scalar.spec.ts +++ b/test/interpreter/scalar.spec.ts @@ -1,8 +1,7 @@ -import {CellError, ErrorType} from '../../src/Cell' +import {CellError, ErrorType} from '../../src' import {Config} from '../../src/Config' import {DateHelper} from '../../src/DateHelper' import {ArithmeticHelper, max, min} from '../../src/interpreter/ArithmeticHelper' -import '../testConfig' import {NumberLiteralHelper} from '../../src/NumberLiteralHelper' describe('nonstrictadd', () => { diff --git a/test/parser/boolean-operators.spec.ts b/test/parser/boolean-operators.spec.ts index d964cc337f..df1db066a8 100644 --- a/test/parser/boolean-operators.spec.ts +++ b/test/parser/boolean-operators.spec.ts @@ -12,6 +12,7 @@ import { NotEqualOpAst, ParserWithCaching, } from '../../src/parser' +import '../testConfig' describe('Parser - Boolean operators', () => { it('Equals operator', () => { diff --git a/test/parser/compute-hash-from-ast.spec.ts b/test/parser/compute-hash-from-ast.spec.ts index 369d5bab5e..9c103316af 100644 --- a/test/parser/compute-hash-from-ast.spec.ts +++ b/test/parser/compute-hash-from-ast.spec.ts @@ -3,11 +3,11 @@ import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' import {buildTranslationPackage, enGB, plPL} from '../../src/i18n' import {buildLexerConfig, FormulaLexer, ParserWithCaching} from '../../src/parser' -import {adr} from '../testUtils' +import {adr, unregisterAllLanguages} from '../testUtils' describe('Compute hash from ast', () => { beforeEach(() => { - HyperFormula.unregisterAllLanguages() + unregisterAllLanguages() HyperFormula.registerLanguage('plPL', plPL) HyperFormula.registerLanguage('enGB', enGB) }) diff --git a/test/parser/compute-hash-from-tokens.spec.ts b/test/parser/compute-hash-from-tokens.spec.ts index 316ba8237e..ae0f7fa181 100644 --- a/test/parser/compute-hash-from-tokens.spec.ts +++ b/test/parser/compute-hash-from-tokens.spec.ts @@ -4,6 +4,7 @@ import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' import {enGB, plPL} from '../../src/i18n' import {buildLexerConfig, FormulaLexer, ParserWithCaching} from '../../src/parser' +import {unregisterAllLanguages} from '../testUtils' describe('computeHashFromTokens', () => { const computeFunc = (code: string, address: SimpleCellAddress, language: string = 'enGB'): string => { @@ -16,7 +17,7 @@ describe('computeHashFromTokens', () => { return parser.computeHashFromTokens(tokens, address) } beforeEach(() => { - HyperFormula.unregisterAllLanguages() + unregisterAllLanguages() HyperFormula.registerLanguage('plPL', plPL) HyperFormula.registerLanguage('enGB', enGB) }) diff --git a/test/parser/concatenate-operator.spec.ts b/test/parser/concatenate-operator.spec.ts index 978318c418..f56bbb67d9 100644 --- a/test/parser/concatenate-operator.spec.ts +++ b/test/parser/concatenate-operator.spec.ts @@ -3,6 +3,7 @@ import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' import {buildTranslationPackage, enGB} from '../../src/i18n' import {AstNodeType, ConcatenateOpAst, ParserWithCaching, ProcedureAst} from '../../src/parser' +import '../testConfig' describe('Parser - Concatenate operators', () => { it('Greater than operator', () => { diff --git a/test/parser/parser-caching.spec.ts b/test/parser/parser-caching.spec.ts index ef5e0768d2..ba9f47ae35 100644 --- a/test/parser/parser-caching.spec.ts +++ b/test/parser/parser-caching.spec.ts @@ -5,6 +5,7 @@ import {buildTranslationPackage, enGB} from '../../src/i18n' import { ParserWithCaching, } from '../../src/parser' +import '../testConfig' describe('ParserWithCaching - caching', () => { it('it use cache for similar formulas', () => { diff --git a/test/parser/parser.spec.ts b/test/parser/parser.spec.ts index 4239f90f76..10d1b645e0 100644 --- a/test/parser/parser.spec.ts +++ b/test/parser/parser.spec.ts @@ -27,12 +27,13 @@ import { RowRangeAst } from '../../src/parser/Ast' import {ColumnAddress} from '../../src/parser/ColumnAddress' -import {adr} from '../testUtils' +import {adr, unregisterAllLanguages} from '../testUtils' import {RowAddress} from '../../src/parser/RowAddress' +import '../testConfig' -describe('ParserWithCaching', () => { + describe('ParserWithCaching', () => { beforeEach(() => { - HyperFormula.unregisterAllLanguages() + unregisterAllLanguages() HyperFormula.registerLanguage('plPL', plPL) HyperFormula.registerLanguage('enGB', enGB) }) diff --git a/test/parser/percent-operator.spec.ts b/test/parser/percent-operator.spec.ts index 8d67c97640..0453f7b6d0 100644 --- a/test/parser/percent-operator.spec.ts +++ b/test/parser/percent-operator.spec.ts @@ -4,6 +4,7 @@ import {SheetMapping} from '../../src/DependencyGraph' import {buildTranslationPackage, enGB} from '../../src/i18n' import {AstNodeType, MinusUnaryOpAst, ParserWithCaching, PlusUnaryOpAst, PlusOpAst} from '../../src/parser' import {PercentOpAst, TimesOpAst} from '../../src/parser/Ast' +import '../testConfig' describe('percent', () => { it('should parse % as operator', () => { diff --git a/test/parser/range-offset.spec.ts b/test/parser/range-offset.spec.ts index f246ec1615..0ca0bf675b 100644 --- a/test/parser/range-offset.spec.ts +++ b/test/parser/range-offset.spec.ts @@ -1,9 +1,10 @@ import {simpleCellAddress} from '../../src/Cell' -import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' import {buildTranslationPackage, enGB} from '../../src/i18n' import {AstNodeType, CellRangeAst, ParserWithCaching, ParsingErrorType} from '../../src/parser' import {RangeSheetReferenceType} from '../../src/parser/Ast' +import {Config} from '../../src/Config' +import '../testConfig' describe('Parser - range offset', () => { it('OFFSET - usage with range', () => { diff --git a/test/parser/unparse.spec.ts b/test/parser/unparse.spec.ts index eca2fa57f7..0fa9bad73e 100644 --- a/test/parser/unparse.spec.ts +++ b/test/parser/unparse.spec.ts @@ -4,7 +4,7 @@ import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' import {buildTranslationPackage, enGB, plPL} from '../../src/i18n' import {AstNodeType, buildLexerConfig, ParserWithCaching, Unparser} from '../../src/parser' -import {adr} from '../testUtils' +import {adr, unregisterAllLanguages} from '../testUtils' describe('Unparse', () => { const config = new Config() @@ -18,7 +18,7 @@ describe('Unparse', () => { beforeEach(() => { - HyperFormula.unregisterAllLanguages() + unregisterAllLanguages() HyperFormula.registerLanguage('plPL', plPL) HyperFormula.registerLanguage('enGB', enGB) }) diff --git a/test/parser/volatile-functions-detection.spec.ts b/test/parser/volatile-functions-detection.spec.ts index 305d7408e9..1a93f94e43 100644 --- a/test/parser/volatile-functions-detection.spec.ts +++ b/test/parser/volatile-functions-detection.spec.ts @@ -5,6 +5,7 @@ import {buildTranslationPackage, enGB} from '../../src/i18n' import { ParserWithCaching, } from '../../src/parser' +import '../testConfig' describe('ParserWithCaching - volatile functions detection', () => { it('detects volatile functions', () => { diff --git a/test/testConfig.ts b/test/testConfig.ts index 821d9a290e..b33b31eec7 100644 --- a/test/testConfig.ts +++ b/test/testConfig.ts @@ -1,13 +1,11 @@ import {HyperFormula} from '../src' import {Config} from '../src/Config' import {AlwaysSparse} from '../src/DependencyGraph/AddressMapping/ChooseAddressMappingPolicy' -import {enGB} from '../src/i18n' +import {languages} from '../src/i18n' +import {unregisterAllLanguages} from './testUtils' Config.defaultConfig = Object.assign({}, Config.defaultConfig, { chooseAddressMappingPolicy: new AlwaysSparse(), - dateFormats: ['MM/DD/YYYY'], - functionArgSeparator: ',', - language: 'enGB', functionPlugins: [], gpuMode: 'cpu', matrixDetection: false, @@ -15,6 +13,7 @@ Config.defaultConfig = Object.assign({}, Config.defaultConfig, { }) beforeEach(() => { - HyperFormula.unregisterAllLanguages() - HyperFormula.registerLanguage('enGB', enGB) + unregisterAllLanguages() + const defaultLanguage = Config.defaultConfig.language + HyperFormula.registerLanguage(defaultLanguage, languages[defaultLanguage]) }) diff --git a/test/testUtils.ts b/test/testUtils.ts index 6aeed24cef..a3521e447d 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -100,7 +100,7 @@ const colNumber = (input: string): number => { export function detailedError(errorType: ErrorType, message?: string, config?: Config): DetailedCellError { config = new Config(config) const error = new CellError(errorType, message) - return new DetailedCellError(error, config.getErrorTranslationFor(errorType)) + return new DetailedCellError(error, config.translationPackage.getErrorTranslation(errorType)) } export const expectEngineToBeTheSameAs = (actual: HyperFormula, expected: HyperFormula) => { @@ -124,3 +124,12 @@ export function expectCloseTo(actual: InternalCellValue, expected: number, preci expect(Math.abs(actual - expected)).toBeLessThan(precision) } } + +export function unregisterAllLanguages() { + for (const langCode of HyperFormula.getRegisteredLanguagesCodes()) { +// if (langCode !== Config.defaultConfig.language) + { + HyperFormula.unregisterLanguage(langCode) + } + } +}