-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
334 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Localizer } from './localizer'; | ||
export type { WorkspaceConfig } from './workspace'; | ||
export { Workspace } from './workspace'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import i18next, { i18n } from 'i18next'; | ||
|
||
export class Localizer { | ||
private readonly i18n: i18n; | ||
private readonly backend: LocalBackend; | ||
|
||
constructor(language?: string) { | ||
this.backend = new LocalBackend(); | ||
this.i18n = i18next | ||
.createInstance({ | ||
lng: language, | ||
fallbackLng: 'en', | ||
partialBundledLanguages: true, | ||
ns: [], | ||
resources: {}, | ||
}) | ||
.use(this.backend); | ||
} | ||
|
||
get language(): string { | ||
return this.i18n.language; | ||
} | ||
|
||
async init(): Promise<void> { | ||
await this.i18n.init(); | ||
} | ||
|
||
async addNamespace(namespace: string, loader: (language: string) => Promise<unknown>): Promise<void> { | ||
if (this.i18n.hasLoadedNamespace(namespace)) { | ||
return; | ||
} | ||
this.backend.addNamespace(namespace, loader); | ||
await this.i18n.loadNamespaces(namespace); | ||
} | ||
|
||
async changeLanguage(language: string): Promise<void> { | ||
await this.i18n.changeLanguage(language); | ||
} | ||
|
||
t(key: string, options?: Record<string, string>): string { | ||
return this.i18n.t(key, options); | ||
} | ||
} | ||
|
||
class LocalBackend { | ||
private readonly namespaceLoaders = new Map<string, (language: string) => Promise<unknown>>(); | ||
readonly type = 'backend'; | ||
|
||
init(_services: unknown, _backendOptions: unknown, _i18nextOptions: unknown): void { | ||
// do nothing | ||
} | ||
|
||
addNamespace(namespace: string, loader: (language: string) => Promise<unknown>): void { | ||
this.namespaceLoaders.set(namespace, loader); | ||
} | ||
|
||
read(language: string, namespace: string, callback: (err: unknown, data?: unknown) => void): void { | ||
const loader = this.namespaceLoaders.get(namespace); | ||
if (loader == null) { | ||
callback(new Error(`No loader for namespace ${namespace}`)); | ||
return; | ||
} | ||
loader(language) | ||
.then((data) => { | ||
callback(null, data); | ||
}) | ||
.catch(callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import library from '@repo/eslint-config/library.mjs'; | ||
|
||
export default [ | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
}, | ||
}, | ||
}, | ||
...library, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@sillsdev/lynx-examples", | ||
"version": "1.0.0", | ||
"description": "", | ||
"type": "module", | ||
"types": "./dist/index.d.ts", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"build": "tsup-node src/index.ts --dts --format cjs,esm --clean --sourcemap", | ||
"dev": "tsup-node src/index.ts --dts --format cjs,esm --watch --sourcemap", | ||
"check-types": "tsc --noEmit", | ||
"lint": "eslint .", | ||
"test": "vitest", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"keywords": [], | ||
"author": "SIL Global", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@sillsdev/lynx": "*" | ||
}, | ||
"devDependencies": { | ||
"@repo/eslint-config": "*", | ||
"@repo/typescript-config": "*", | ||
"@vitest/coverage-v8": "^2.1.4", | ||
"eslint": "^9.9.1", | ||
"tsup": "^8.3.0", | ||
"typescript": "^5.5.4", | ||
"vitest": "^2.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { SimpleQuoteFormattingProvider } from './simple-quote-formatting-provider'; | ||
export { VerseOrderDiagnosticProvider } from './verse-order-diagnostic-provider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"missingVerse": { | ||
"description": "Verse {{verse}} is missing from chapter {{chapter}}. Insert the missing verse to fix.", | ||
"fixTitle": "Insert missing verse" | ||
}, | ||
"verseOutOfOrder": { | ||
"description": "Verse {{verse}} occurs out of order in chapter {{chapter}}." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"missingVerse": { | ||
"description": "Falta el versículo {{verse}} del capítulo {{chapter}}. Inserta el versículo que falta para arreglarlo.", | ||
"fixTitle": "Inserta el versículo que falta" | ||
}, | ||
"verseOutOfOrder": { | ||
"description": "El versículo {{verse}} aparece fuera de orden en el capítulo {{chapter}}." | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
...de/src/smart-quote-formatting-provider.ts → ...s/src/simple-quote-formatting-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.