-
Notifications
You must be signed in to change notification settings - Fork 47
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
25 changed files
with
1,315 additions
and
99 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
Large diffs are not rendered by default.
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
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,9 +1,6 @@ | ||
import en from '../locale/en-US.json'; | ||
import type LocaleText from './LocaleText'; | ||
import Locales from './Locales'; | ||
|
||
const DefaultLocale = en as unknown as LocaleText; | ||
|
||
export const DefaultLocales = new Locales([DefaultLocale], DefaultLocale); | ||
|
||
export default DefaultLocale; |
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,7 @@ | ||
import DefaultLocale from './DefaultLocale'; | ||
import Locales from './Locales'; | ||
import concretize from './concretize'; | ||
|
||
const DefaultLocales = new Locales(concretize, [DefaultLocale], DefaultLocale); | ||
|
||
export { DefaultLocales as default }; |
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,51 @@ | ||
import type { TemplateInput } from './Locales'; | ||
import type Locales from './Locales'; | ||
import { isUnwritten, withoutAnnotations } from './LocaleText'; | ||
import { toMarkup } from '@parser/toMarkup'; | ||
import Markup from '@nodes/Markup'; | ||
|
||
/** We maintain cache a mapping from template strings to compiled markup, since they are fixed structures. | ||
* We just reuse them with different inputs.*/ | ||
const TemplateToMarkupCache: Map<string, Markup> = new Map(); | ||
|
||
export type Concretizer = ( | ||
locales: Locales, | ||
template: string, | ||
...inputs: TemplateInput[] | ||
) => Markup; | ||
|
||
export function concretizeOrUndefined( | ||
locales: Locales, | ||
template: string, | ||
...inputs: TemplateInput[] | ||
): Markup | undefined { | ||
// Not written? Return the TBD string. | ||
if (template === '' || isUnwritten(template)) | ||
return Markup.words(locales.get((l) => l.ui.template.unwritten)); | ||
|
||
// Remove annotations. | ||
template = withoutAnnotations(template); | ||
|
||
// See if we've cached this template. | ||
let markup = TemplateToMarkupCache.get(template); | ||
if (markup === undefined) { | ||
[markup] = toMarkup(template); | ||
TemplateToMarkupCache.set(template, markup); | ||
} | ||
|
||
// Now concretize the markup with the given inputs. | ||
return markup.concretize(locales, inputs); | ||
} | ||
|
||
export default function concretize( | ||
locales: Locales, | ||
template: string, | ||
...inputs: TemplateInput[] | ||
): Markup { | ||
return ( | ||
concretizeOrUndefined(locales, template, ...inputs) ?? | ||
Markup.words( | ||
`${locales.get((l) => l.ui.template.unparsable)}: ${template}`, | ||
) | ||
); | ||
} |
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
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
Oops, something went wrong.