-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow implicit key for <Trans> when omitting i18nKey prop
closes #53
- Loading branch information
1 parent
0b34796
commit c6f13e3
Showing
4 changed files
with
205 additions
and
7 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
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,14 +1,21 @@ | ||
--- | ||
import { interpolate } from "../utils"; | ||
import { interpolate, createReferenceStringFromHTML } from "../utils"; | ||
export interface Props { | ||
i18nKey: string; | ||
i18nKey?: string; | ||
ns?: string; | ||
} | ||
const { i18nKey, ns } = Astro.props; | ||
const referenceString = await Astro.slots.render("default"); | ||
let key: string; | ||
if (typeof i18nKey === "string") { | ||
key = i18nKey; | ||
} else { | ||
key = createReferenceStringFromHTML(referenceString); | ||
} | ||
--- | ||
|
||
<Fragment set:html={interpolate(i18nKey, referenceString, ns)} /> | ||
<Fragment set:html={interpolate(key, referenceString, ns)} /> |
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