or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
$localize - message-id support
Background
The original design doc for
$localize
avoids message-ids for Angular v9 since the template compiler does not need to generate messages based on ids.Therefore the original implementation for
$localize
relies upon the source-message as the "key" for looking up translations. For example give then following template:The Angular compiler generates the following source-message, which is then used as a translation-key.
Problems with source-message as translation-key
Multiple meanings
It is possible for there to be more than one translation for a source message depending upon the context, requiring a custom/manual id:
In the curent version of Angular the message "meaning" is combined with the source-message to compute the id.
Whitespace removal
In order to support consistent rendering of expandable ICU messages (containing markup), the source-message has its whitespace removed, if
preserveWhitespace: false
. This means that the source-message in the template is different to that extracted into translation files. In the example given in Background the source-message in the template is:while in the translation file it is:
This prevents accurate translation lookup based on the source-message string.
Proposal
Localized string syntax
Extend the format of localized strings to allow "meaning", "description" and "message-id" to be provided. This metadata is provided at the start of the string marked by colons. Each of these is optional. For example:
The delimiters within the colons are chosen to match those already used in Angular templates. For example:
If a source-message actually starts with a colon then it must be escaped with a backslash. For example:
This approach is similar to that already implemented for named placeholders: the substitution is post-fixed by a colon delimited placeholder name. For example:
Template generation
The template source-message strings are not guaranteed to be identical to those in translation files. See Whitespace removal) above. Therefore we must provide the computed id when generating
$localize
tagged strings in template generation. For example:This ensures that translation of this message is based on the message-id and not the source-message.
Translation matching
Use the message-id as the key when looking up translations rather than the source-message.
If a source-message does not provide a custom message-id then compute one.
Computed message-ids are generated using the same algorithm as XLIFF2 and XMB/XTB formats. This is implemented in the
decimalDigest()
function.$localize.translate() implementation
The
$localize()
function passes themessageParts
andexpressions
to the$localize.translate()
run-time translation function. The current implementation computes the source-message and uses that as the translation-key.Modify this function to compute the message-id instead and use that as the translation-key.
Translation storage
Internally each translation is stored as a
ParsedTranslation
object, which is kept in a lookup table.Modify this lookup table so that the key is the message-id.
Loading translations
The
loadTranslations()
function accepts atranslations
argument:Change this function to accept a
translations
argument that is a map of message-ids instead of source-messages:When calling
loadTranslations()
, the caller is now responsible for providing the message-id of each translation: either custom message-ids or computed viadecimalDigest()
.If the translations are loaded from a formatted translation file that uses the same algorithm as
decimalDigest()
, e.g. XLIFF2 or XTB, then the loader can just use the message-ids directly.If the translations are loaded from a formatted translation file uses a different digest algorithm, e.g. XLIFF 1.2, then the loader must convert the given message-id before calling
loadTranslations()
. This is done as follows:decimalDigest()
algorithm.