From a9edcb970d7e40f7a0efd73f900eb8a9742a49bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Orli=C5=84ski?= Date: Sun, 9 Jan 2022 16:45:28 +0100 Subject: [PATCH] :sparkles: (shared) Add lang attribute support --- packages/@shared/types.ts | 17 +++++++++++++++++ packages/@shared/util.ts | 3 ++- packages/react/_debug/main.tsx | 1 + packages/react/lib/Giscus.tsx | 4 +++- packages/react/package.json | 3 ++- packages/svelte/_debug/App.svelte | 1 + packages/svelte/lib/Giscus.svelte | 4 +++- packages/vue/_debug/App.vue | 1 + packages/vue/lib/Giscus.tsx | 4 ++++ yarn.lock | 16 +++++++++++++++- 10 files changed, 49 insertions(+), 5 deletions(-) diff --git a/packages/@shared/types.ts b/packages/@shared/types.ts index 1c9dbda6..ebb2fca0 100644 --- a/packages/@shared/types.ts +++ b/packages/@shared/types.ts @@ -10,6 +10,7 @@ type Giscus = { theme?: Theme reactionsEnabled?: BooleanString emitMetadata?: BooleanString + lang?: Lang } type BooleanString = '0' | '1' @@ -31,4 +32,20 @@ type Theme = | 'transparent_dark' | `https://${string}` +type Lang = + | 'en' + | 'fr' + | 'de' + | 'gsw' + | 'es' + | 'it' + | 'ja' + | 'ko' + | 'pl' + | 'id' + | 'ro' + | 'zh-CN' + | 'zh-TW' + | string + export type { GiscusProps, Giscus, Session, Repo, Mapping, Theme } diff --git a/packages/@shared/util.ts b/packages/@shared/util.ts index 3274d61b..b2f9143b 100644 --- a/packages/@shared/util.ts +++ b/packages/@shared/util.ts @@ -26,6 +26,7 @@ export function getIframeSrc({ theme = 'light', reactionsEnabled = '1', emitMetadata = '0', + lang = 'en', session, origin = location.href }: Giscus & Session & { origin?: string }) { @@ -69,7 +70,7 @@ export function getIframeSrc({ break } - return `${GISCUS_ORIGIN}/widget?${new URLSearchParams(params)}` + return `${GISCUS_ORIGIN}/${lang}/widget?${new URLSearchParams(params)}` } export function addDefaultStyles() { diff --git a/packages/react/_debug/main.tsx b/packages/react/_debug/main.tsx index 89359fdc..42f58cb9 100644 --- a/packages/react/_debug/main.tsx +++ b/packages/react/_debug/main.tsx @@ -14,6 +14,7 @@ ReactDOM.render( reactionsEnabled="1" emitMetadata="0" theme="light" + lang="en" /> , document.getElementById('root') diff --git a/packages/react/lib/Giscus.tsx b/packages/react/lib/Giscus.tsx index 6cca187b..30c485e8 100644 --- a/packages/react/lib/Giscus.tsx +++ b/packages/react/lib/Giscus.tsx @@ -76,7 +76,8 @@ export default function Giscus({ term, theme, reactionsEnabled, - emitMetadata + emitMetadata, + lang }: GiscusProps) { const [isMounted, setIsMounted] = useState(false) useEffect(() => setIsMounted(true), []) @@ -93,6 +94,7 @@ export default function Giscus({ theme={theme} reactionsEnabled={reactionsEnabled} emitMetadata={emitMetadata} + lang={lang} /> ) } diff --git a/packages/react/package.json b/packages/react/package.json index d299bb5a..4e25ff54 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -35,7 +35,8 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.3.1", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "prop-types": "^15.7.2" }, "author": { "name": "laymonage", diff --git a/packages/svelte/_debug/App.svelte b/packages/svelte/_debug/App.svelte index 5f96ab64..5544aeb9 100644 --- a/packages/svelte/_debug/App.svelte +++ b/packages/svelte/_debug/App.svelte @@ -13,5 +13,6 @@ reactionsEnabled="1" emitMetadata="0" theme="light" + lang="en" /> diff --git a/packages/svelte/lib/Giscus.svelte b/packages/svelte/lib/Giscus.svelte index 0ca68506..8a6121fc 100644 --- a/packages/svelte/lib/Giscus.svelte +++ b/packages/svelte/lib/Giscus.svelte @@ -18,6 +18,7 @@ export let categoryId: GiscusProps['categoryId'] = '' export let mapping: GiscusProps['mapping'] export let term: GiscusProps['term'] = '' + export let lang: GiscusProps['lang'] = 'en' export let theme: GiscusProps['theme'] = 'light' export let reactionsEnabled: GiscusProps['reactionsEnabled'] = '1' export let emitMetadata: GiscusProps['emitMetadata'] = '0' @@ -30,10 +31,11 @@ categoryId, mapping, term, + lang, theme, reactionsEnabled, emitMetadata, - session + session, }) onMount(() => { diff --git a/packages/vue/_debug/App.vue b/packages/vue/_debug/App.vue index 624f2102..e91cd17e 100644 --- a/packages/vue/_debug/App.vue +++ b/packages/vue/_debug/App.vue @@ -9,6 +9,7 @@ reactionsEnabled="1" emitMetadata="0" theme="light" + lang="en" /> diff --git a/packages/vue/lib/Giscus.tsx b/packages/vue/lib/Giscus.tsx index dd49ad50..f7bf610e 100644 --- a/packages/vue/lib/Giscus.tsx +++ b/packages/vue/lib/Giscus.tsx @@ -35,6 +35,10 @@ const Giscus = defineComponent({ required: true }, term: String as PropType, + lang: { + type: String as PropType, + default: 'en' + }, theme: { type: String as PropType, default: 'light' diff --git a/yarn.lock b/yarn.lock index 40f0da3b..79651013 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4369,7 +4369,7 @@ longest@^2.0.1: resolved "https://registry.yarnpkg.com/longest/-/longest-2.0.1.tgz#781e183296aa94f6d4d916dc335d0d17aefa23f8" integrity sha1-eB4YMpaqlPbU2RbcM10NF676I/g= -loose-envify@^1.0.0, loose-envify@^1.1.0: +loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -5527,6 +5527,15 @@ promzard@^0.3.0: dependencies: read "1" +prop-types@^15.7.2: + version "15.8.1" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" + integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== + dependencies: + loose-envify "^1.4.0" + object-assign "^4.1.1" + react-is "^16.13.1" + property-information@^5.1.0: version "5.6.0" resolved "https://registry.yarnpkg.com/property-information/-/property-information-5.6.0.tgz#61675545fb23002f245c6540ec46077d4da3ed69" @@ -5741,6 +5750,11 @@ react-dom@^17.0.2: object-assign "^4.1.1" scheduler "^0.20.2" +react-is@^16.13.1: + version "16.13.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" + integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== + react-refresh@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.10.0.tgz#2f536c9660c0b9b1d500684d9e52a65e7404f7e3"