Skip to content

Commit

Permalink
✨ (shared) Add lang attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-orlinski authored and laymonage committed Feb 3, 2022
1 parent 273657b commit a9edcb9
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 5 deletions.
17 changes: 17 additions & 0 deletions packages/@shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Giscus = {
theme?: Theme
reactionsEnabled?: BooleanString
emitMetadata?: BooleanString
lang?: Lang
}

type BooleanString = '0' | '1'
Expand All @@ -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 }
3 changes: 2 additions & 1 deletion packages/@shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function getIframeSrc({
theme = 'light',
reactionsEnabled = '1',
emitMetadata = '0',
lang = 'en',
session,
origin = location.href
}: Giscus & Session & { origin?: string }) {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions packages/react/_debug/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ReactDOM.render(
reactionsEnabled="1"
emitMetadata="0"
theme="light"
lang="en"
/>
</React.StrictMode>,
document.getElementById('root')
Expand Down
4 changes: 3 additions & 1 deletion packages/react/lib/Giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export default function Giscus({
term,
theme,
reactionsEnabled,
emitMetadata
emitMetadata,
lang
}: GiscusProps) {
const [isMounted, setIsMounted] = useState(false)
useEffect(() => setIsMounted(true), [])
Expand All @@ -93,6 +94,7 @@ export default function Giscus({
theme={theme}
reactionsEnabled={reactionsEnabled}
emitMetadata={emitMetadata}
lang={lang}
/>
)
}
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/_debug/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
reactionsEnabled="1"
emitMetadata="0"
theme="light"
lang="en"
/>
</main>
4 changes: 3 additions & 1 deletion packages/svelte/lib/Giscus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,10 +31,11 @@
categoryId,
mapping,
term,
lang,
theme,
reactionsEnabled,
emitMetadata,
session
session,
})
onMount(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/vue/_debug/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
reactionsEnabled="1"
emitMetadata="0"
theme="light"
lang="en"
/>
</template>

Expand Down
4 changes: 4 additions & 0 deletions packages/vue/lib/Giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const Giscus = defineComponent({
required: true
},
term: String as PropType<GiscusProps['term']>,
lang: {
type: String as PropType<GiscusProps['lang']>,
default: 'en'
},
theme: {
type: String as PropType<GiscusProps['theme']>,
default: 'light'
Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a9edcb9

Please sign in to comment.