Skip to content

Commit

Permalink
feat(v2): Add Interpolate / interpolate APIs + complete theme transla…
Browse files Browse the repository at this point in the history
…tions (#4295)

* WIP: refactor team profile cards

* Add Interpolate / interpolate APIs

* Add interpolate snapshot test

* comments

* fix Interpolate TS types

* Interpolate should handle numbers and other JS types

* translate BlogPostItem

* interpolate translate() fn + add translations for blog post tag header

* localize the LastUpdated component

* translate DocVersionSuggestions

* fix test

* add some new translations

* Add node script to easily update the theme default translations

* fix translation extractor bug due to translate() dynamic values

* use ICU placeholder syntax

* refactor month key

* order

* team  page translation improvements

* Add interpolation doc + improve i18n doc
  • Loading branch information
slorber authored Feb 26, 2021
1 parent cdcd0f0 commit 1734975
Show file tree
Hide file tree
Showing 29 changed files with 1,459 additions and 473 deletions.
59 changes: 53 additions & 6 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,63 @@ declare module '@docusaurus/Link' {
export default Link;
}

declare module '@docusaurus/Interpolate' {
import type {ReactNode} from 'react';

// TODO use TS template literal feature to make values typesafe!
// (requires upgrading TS first)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type ExtractInterpolatePlaceholders<Str extends string> = string;

export type InterpolateValues<
Str extends string,
Value extends ReactNode
> = Record<ExtractInterpolatePlaceholders<Str>, Value>;

// TS function overload: if all the values are plain strings, then interpolate returns a simple string
export function interpolate<Str extends string>(
text: Str,
values?: InterpolateValues<Str, string | number>,
): string;

// If values contain any ReactNode, then the return is a ReactNode
export function interpolate<Str extends string, Value extends ReactNode>(
text: Str,
values?: InterpolateValues<Str, Value>,
): ReactNode;

export type InterpolateProps<Str extends string> = {
children: Str;
values?: InterpolateValues<Str, ReactNode>;
};

export default function Interpolate<Str extends string>(
props: InterpolateProps<Str>,
): JSX.Element;
}

declare module '@docusaurus/Translate' {
type TranslateProps = {children: string; id?: string; description?: string};
const Translate: (props: TranslateProps) => JSX.Element;
export default Translate;
import type {
InterpolateProps,
InterpolateValues,
} from '@docusaurus/Interpolate';

export function translate(param: {
message: string;
type TranslateProps<Str extends string> = InterpolateProps<Str> & {
id?: string;
description?: string;
}): string;
};
export default function Translate<Str extends string>(
props: TranslateProps<Str>,
): JSX.Element;

export function translate<Str extends string>(
param: {
message: Str;
id?: string;
description?: string;
},
values?: InterpolateValues<Str, string | number>,
): string;
}

declare module '@docusaurus/router' {
Expand Down
82 changes: 53 additions & 29 deletions packages/docusaurus-theme-classic/codeTranslations/base.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
{
"theme.NotFound.title": "Page Not Found",
"theme.AnnouncementBar.closeButtonAriaLabel": "Close",
"theme.CodeBlock.copied": "Copied",
"theme.CodeBlock.copy": "Copy",
"theme.CodeBlock.copyButtonAriaLabel": "Copy code to clipboard",
"theme.NotFound.p1": "We could not find what you were looking for.",
"theme.NotFound.p2": "Please contact the owner of the site that linked you to the original URL and let them know their link is broken.",
"theme.AnnouncementBar.closeButtonAriaLabel": "Close",
"theme.NotFound.title": "Page Not Found",
"theme.Playground.liveEditor": "Live Editor",
"theme.Playground.result": "Result",
"theme.PwaReloadPopup.closeButtonAriaLabel": "Close",
"theme.PwaReloadPopup.info": "New version available",
"theme.PwaReloadPopup.refreshButtonText": "Refresh",
"theme.SearchBar.label": "Search",
"theme.SearchPage.algoliaLabel": "Search by Algolia",
"theme.SearchPage.emptyResultsTitle": "Search the documentation",
"theme.SearchPage.existingResultsTitle": "Search results for",
"theme.SearchPage.fetchingNewResults": "Fetching new results...",
"theme.SearchPage.inputLabel": "Search",
"theme.SearchPage.inputPlaceholder": "Type your search here",
"theme.SearchPage.noResultsText": "No results were found",
"theme.blog.paginator.navAriaLabel": "Blog list page navigation",
"theme.blog.paginator.newerEntries": "Newer Entries",
"theme.blog.paginator.olderEntries": "Older Entries",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.nPosts": "{count} posts",
"theme.blog.post.onePost": "One post",
"theme.blog.post.paginator.navAriaLabel": "Blog post page navigation",
"theme.blog.post.paginator.newerPost": "Newer Post",
"theme.blog.post.paginator.olderPost": "Older Post",
"theme.blog.post.readMore": "Read More",
"theme.tags.tagsPageLink": "View All Tags",
"theme.tags.tagsPageTitle": "Tags",
"theme.tags.tagsListLabel": "Tags:",
"theme.CodeBlock.copyButtonAriaLabel": "Copy code to clipboard",
"theme.CodeBlock.copied": "Copied",
"theme.CodeBlock.copy": "Copy",
"theme.blog.post.readingTime": "{readingTime} min read",
"theme.blog.tagTitle": "{nPosts} tagged with \"{tagName}\"",
"theme.common.editThisPage": "Edit this page",
"theme.common.headingLinkTitle": "Direct link to heading",
"theme.common.month.april": "April",
"theme.common.month.august": "August",
"theme.common.month.december": "December",
"theme.common.month.february": "February",
"theme.common.month.january": "January",
"theme.common.month.july": "July",
"theme.common.month.june": "June",
"theme.common.month.march": "March",
"theme.common.month.may": "May",
"theme.common.month.november": "November",
"theme.common.month.october": "October",
"theme.common.month.september": "September",
"theme.common.skipToMainContent": "Skip to main content",
"theme.docs.paginator.navAriaLabel": "Docs pages navigation",
"theme.docs.paginator.previous": "Previous",
"theme.docs.paginator.next": "Next",
"theme.docs.sidebar.expandButtonTitle": "Expand sidebar",
"theme.docs.paginator.previous": "Previous",
"theme.docs.sidebar.collapseButtonAriaLabel": "Collapse sidebar",
"theme.docs.sidebar.collapseButtonTitle": "Collapse sidebar",
"theme.docs.sidebar.expandButtonAriaLabel": "Expand sidebar",
"theme.docs.sidebar.expandButtonTitle": "Expand sidebar",
"theme.docs.sidebar.responsiveCloseButtonLabel": "Close menu",
"theme.docs.sidebar.responsiveOpenButtonLabel": "Open menu",
"theme.docs.sidebar.collapseButtonTitle": "Collapse sidebar",
"theme.docs.sidebar.collapseButtonAriaLabel": "Collapse sidebar",
"theme.common.editThisPage": "Edit this page",
"theme.common.headingLinkTitle": "Direct link to heading",
"theme.common.skipToMainContent": "Skip to main content",
"theme.SearchPage.existingResultsTitle": "Search results for",
"theme.SearchPage.emptyResultsTitle": "Search the documentation",
"theme.SearchPage.inputPlaceholder": "Type your search here",
"theme.SearchPage.inputLabel": "Search",
"theme.SearchPage.algoliaLabel": "Search by Algolia",
"theme.SearchPage.noResultsText": "No results were found",
"theme.SearchPage.fetchingNewResults": "Fetching new results...",
"theme.SearchBar.label": "Search",
"theme.PwaReloadPopup.info": "New version available",
"theme.PwaReloadPopup.refreshButtonText": "Refresh",
"theme.PwaReloadPopup.closeButtonAriaLabel": "Close",
"theme.Playground.liveEditor": "Live Editor",
"theme.Playground.result": "Result"
}
"theme.docs.versions.latestVersionLinkLabel": "latest version",
"theme.docs.versions.latestVersionSuggestionLabel": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).",
"theme.docs.versions.unmaintainedVersionLabel": "This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.",
"theme.docs.versions.unreleasedVersionLabel": "This is unreleased documentation for {siteTitle} {versionLabel} version.",
"theme.lastUpdated.atDate": "on {date}",
"theme.lastUpdated.byUser": "by {user}",
"theme.lastUpdated.lastUpdatedAtBy": "Last updated{atDate}{byUser}",
"theme.tags.tagsListLabel": "Tags:",
"theme.tags.tagsPageLink": "View All Tags",
"theme.tags.tagsPageTitle": "Tags"
}
110 changes: 67 additions & 43 deletions packages/docusaurus-theme-classic/codeTranslations/de.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
{
"theme.NotFound.title": "Seite nicht gefunden",
"theme.NotFound.p1": "Wir konnten nicht finden, wonach Sie gesucht haben.",
"theme.NotFound.p2": "Bitte kontaktieren Sie den Besitzer der Seite, die Sie mit der ursprünglichen URL verlinkt hat, und teilen Sie ihm mit, dass der Link nicht mehr funktioniert.",
"theme.AnnouncementBar.closeButtonAriaLabel": "Schließen",
"theme.blog.paginator.navAriaLabel": "Navigation der Blog-Listenseite",
"theme.blog.paginator.newerEntries": "Neuere Einträge",
"theme.blog.paginator.olderEntries": "Ältere Einträge",
"theme.blog.post.paginator.navAriaLabel": "Blog Post Seiten Navigation",
"theme.blog.post.paginator.newerPost": "Neuer Post",
"theme.blog.post.paginator.olderPost": "Älterer Post",
"theme.blog.post.readMore": "Mehr lesen",
"theme.tags.tagsPageLink": "Alle Tags anzeigen",
"theme.tags.tagsPageTitle": "Tags",
"theme.tags.tagsListLabel": "Tags:",
"theme.CodeBlock.copyButtonAriaLabel": "In die Zwischenablage kopieren",
"theme.CodeBlock.copied": "Kopiert",
"theme.CodeBlock.copy": "Kopieren",
"theme.docs.paginator.navAriaLabel": "Dokumentation Seiten Navigation",
"theme.docs.paginator.previous": "Zurück",
"theme.docs.paginator.next": "Weiter",
"theme.docs.sidebar.expandButtonTitle": "Seitenleiste ausklappen",
"theme.docs.sidebar.expandButtonAriaLabel": "Seitenleiste ausklappen",
"theme.docs.sidebar.responsiveCloseButtonLabel": "Menü schließen",
"theme.docs.sidebar.responsiveOpenButtonLabel": "Menü öffenen",
"theme.docs.sidebar.collapseButtonTitle": "Seitenleiste einklappen",
"theme.docs.sidebar.collapseButtonAriaLabel": "Seitenleiste einklappen",
"theme.common.editThisPage": "Diese Seite bearbeiten",
"theme.common.headingLinkTitle": "Direkter Link zur Überschrift",
"theme.common.skipToMainContent": "Zum Hauptinhalt springen",
"theme.SearchPage.existingResultsTitle": "Suchergebnisse für",
"theme.SearchPage.emptyResultsTitle": "Suche in der Dokumentation",
"theme.SearchPage.inputPlaceholder": "Geben Sie hier Ihre Suche ein",
"theme.SearchPage.inputLabel": "Suche",
"theme.SearchPage.algoliaLabel": "Suche von Algolia",
"theme.SearchPage.noResultsText": "Es wurden keine Ergebnisse gefunden",
"theme.SearchPage.fetchingNewResults": "Neue Ergebnisse abrufen...",
"theme.SearchBar.label": "Suche",
"theme.PwaReloadPopup.info": "Neue Version verfügbar",
"theme.PwaReloadPopup.refreshButtonText": "Aktualisieren",
"theme.PwaReloadPopup.closeButtonAriaLabel": "Schließen",
"theme.Playground.liveEditor": "Live Editor",
"theme.Playground.result": "Ergebnisse"
}
"theme.AnnouncementBar.closeButtonAriaLabel": "Schließen",
"theme.CodeBlock.copied": "Kopiert",
"theme.CodeBlock.copy": "Kopieren",
"theme.CodeBlock.copyButtonAriaLabel": "In die Zwischenablage kopieren",
"theme.NotFound.p1": "Wir konnten nicht finden, wonach Sie gesucht haben.",
"theme.NotFound.p2": "Bitte kontaktieren Sie den Besitzer der Seite, die Sie mit der ursprünglichen URL verlinkt hat, und teilen Sie ihm mit, dass der Link nicht mehr funktioniert.",
"theme.NotFound.title": "Seite nicht gefunden",
"theme.Playground.liveEditor": "Live Editor",
"theme.Playground.result": "Ergebnisse",
"theme.PwaReloadPopup.closeButtonAriaLabel": "Schließen",
"theme.PwaReloadPopup.info": "Neue Version verfügbar",
"theme.PwaReloadPopup.refreshButtonText": "Aktualisieren",
"theme.SearchBar.label": "Suche",
"theme.SearchPage.algoliaLabel": "Suche von Algolia",
"theme.SearchPage.emptyResultsTitle": "Suche in der Dokumentation",
"theme.SearchPage.existingResultsTitle": "Suchergebnisse für",
"theme.SearchPage.fetchingNewResults": "Neue Ergebnisse abrufen...",
"theme.SearchPage.inputLabel": "Suche",
"theme.SearchPage.inputPlaceholder": "Geben Sie hier Ihre Suche ein",
"theme.SearchPage.noResultsText": "Es wurden keine Ergebnisse gefunden",
"theme.blog.paginator.navAriaLabel": "Navigation der Blog-Listenseite",
"theme.blog.paginator.newerEntries": "Neuere Einträge",
"theme.blog.paginator.olderEntries": "Ältere Einträge",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.nPosts": "{count} posts",
"theme.blog.post.onePost": "One post",
"theme.blog.post.paginator.navAriaLabel": "Blog Post Seiten Navigation",
"theme.blog.post.paginator.newerPost": "Neuer Post",
"theme.blog.post.paginator.olderPost": "Älterer Post",
"theme.blog.post.readMore": "Mehr lesen",
"theme.blog.post.readingTime": "{readingTime} min read",
"theme.blog.tagTitle": "{nPosts} tagged with \"{tagName}\"",
"theme.common.editThisPage": "Diese Seite bearbeiten",
"theme.common.headingLinkTitle": "Direkter Link zur Überschrift",
"theme.common.month.april": "April",
"theme.common.month.august": "August",
"theme.common.month.december": "December",
"theme.common.month.february": "February",
"theme.common.month.january": "January",
"theme.common.month.july": "July",
"theme.common.month.june": "June",
"theme.common.month.march": "March",
"theme.common.month.may": "May",
"theme.common.month.november": "November",
"theme.common.month.october": "October",
"theme.common.month.september": "September",
"theme.common.skipToMainContent": "Zum Hauptinhalt springen",
"theme.docs.paginator.navAriaLabel": "Dokumentation Seiten Navigation",
"theme.docs.paginator.next": "Weiter",
"theme.docs.paginator.previous": "Zurück",
"theme.docs.sidebar.collapseButtonAriaLabel": "Seitenleiste einklappen",
"theme.docs.sidebar.collapseButtonTitle": "Seitenleiste einklappen",
"theme.docs.sidebar.expandButtonAriaLabel": "Seitenleiste ausklappen",
"theme.docs.sidebar.expandButtonTitle": "Seitenleiste ausklappen",
"theme.docs.sidebar.responsiveCloseButtonLabel": "Menü schließen",
"theme.docs.sidebar.responsiveOpenButtonLabel": "Menü öffenen",
"theme.docs.versions.latestVersionLinkLabel": "latest version",
"theme.docs.versions.latestVersionSuggestionLabel": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).",
"theme.docs.versions.unmaintainedVersionLabel": "This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.",
"theme.docs.versions.unreleasedVersionLabel": "This is unreleased documentation for {siteTitle} {versionLabel} version.",
"theme.lastUpdated.atDate": "on {date}",
"theme.lastUpdated.byUser": "by {user}",
"theme.lastUpdated.lastUpdatedAtBy": "Last updated{atDate}{byUser}",
"theme.tags.tagsListLabel": "Tags:",
"theme.tags.tagsPageLink": "Alle Tags anzeigen",
"theme.tags.tagsPageTitle": "Tags"
}
Loading

0 comments on commit 1734975

Please sign in to comment.