"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["2168"],{9621:function(e,t,n){n.r(t),n.d(t,{default:()=>h,frontMatter:()=>a,metadata:()=>s,assets:()=>c,toc:()=>d,contentTitle:()=>l});var s=JSON.parse('{"id":"features/i18n","title":"Internationalization (i18n)","description":"LiveCodes currently supports UI internationalization. By default, the UI language will be automatically detected based on your browser settings.","source":"@site/docs/features/i18n.mdx","sourceDirName":"features","slug":"/features/i18n","permalink":"/docs/features/i18n","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/i18n.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Editor Settings","permalink":"/docs/features/editor-settings"},"next":{"title":"Default Template/Language","permalink":"/docs/features/default-template-language"}}'),o=n("5893"),r=n("65"),i=n("3365");let a={},l="Internationalization (i18n)",c={},d=[{value:"Using SDK",id:"using-sdk",level:2},{value:"Using query params",id:"using-query-params",level:2},{value:"Related",id:"related",level:2}];function u(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"internationalization-i18n",children:"Internationalization (i18n)"})}),"\n","\n",(0,o.jsx)(t.p,{children:"LiveCodes currently supports UI internationalization. By default, the UI language will be automatically detected based on your browser settings."}),"\n",(0,o.jsx)(t.p,{children:"You can easily switch between supported UI languages using the i18n menu, allowing you to explore and use LiveCodes in your preferred language!"}),"\n",(0,o.jsxs)(t.p,{children:["If you are interested in contributing to the translation of LiveCodes, please refer to the ",(0,o.jsx)(t.a,{href:"https://github.com/live-codes/livecodes/blob/develop/docs/docs/contribution/i18n.mdx",children:"i18n Contribution Guide"}),"."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.img,{alt:"I18n menu",src:n(4778).Z+"",width:"2240",height:"1400"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.img,{alt:"LiveCodes in Chinese",src:n(9715).Z+"",width:"2240",height:"1400"})}),"\n",(0,o.jsxs)(t.p,{children:["Demo: (",(0,o.jsx)(t.a,{href:"/docs/features/embeds",children:"Embedded playground"})," with ",(0,o.jsx)(t.code,{children:"appLanguage: 'zh-CN'"}),")"]}),"\n",(0,o.jsx)(i.Z,{template:"javascript",config:{appLanguage:"zh-CN"}}),"\n",(0,o.jsx)(t.h2,{id:"using-sdk",children:"Using SDK"}),"\n",(0,o.jsxs)(t.p,{children:["Set the ",(0,o.jsx)(t.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," property ",(0,o.jsx)(t.a,{href:"/docs/configuration/configuration-object#applanguage",children:(0,o.jsx)(t.code,{children:"appLanguage"})})," to a supported language code."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"import { createPlayground } from 'livecodes';\n\ncreatePlayground('#container', { template: 'javascript', config: { appLanguage: 'auto' } });\n"})}),"\n",(0,o.jsx)(t.h2,{id:"using-query-params",children:"Using query params"}),"\n",(0,o.jsxs)(t.p,{children:["Add the ",(0,o.jsx)(t.a,{href:"/docs/configuration/query-params",children:"query parameter"})," ",(0,o.jsx)(t.code,{children:"appLanguage"})," with your preferred language code."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://livecodes.io?template=javascript&appLanguage=fr",children:"https://livecodes.io?template=javascript&appLanguage=fr"})}),"\n",(0,o.jsx)(t.h2,{id:"related",children:"Related"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"/docs/features/user-settings",children:"User Settings"})}),"\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"/docs/features/editor-settings",children:"Editor Settings"})}),"\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"/docs/configuration/query-params",children:"Query params"})}),"\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://github.com/live-codes/livecodes/blob/develop/docs/docs/contribution/i18n.mdx",children:"i18n Contribution Guide"})}),"\n"]})]})}function h(e={}){let{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(u,{...e})}):u(e)}},4778:function(e,t,n){n.d(t,{Z:function(){return s}});let s=n.p+"assets/images/i18n-1-d9c22be743b90d798d670b9ea63fa811.jpg"},9715:function(e,t,n){n.d(t,{Z:function(){return s}});let s=n.p+"assets/images/i18n-2-fa2bf00ef12a8e4df2ee40ba7a7a9e8d.jpg"},3365:function(e,t,n){n.d(t,{Z:()=>m});var s=n("5893"),o=n("4200"),r=n("7294"),i=n("8294");function a(e){let t=(0,r.useRef)(null),[n,o]=(0,r.useState)(e.className||""),[a,l]=(0,r.useState)(e.style||{}),[c,d]=(0,r.useState)(e.height),[u,h]=(0,r.useState)(),[p,g]=(0,r.useState)(JSON.stringify(e.config||"")),[f,m]=(0,r.useState)("");return(0,r.useEffect)(()=>{if(!t.current)return;let{className:n,style:s,height:r,sdkReady:a,config:c,...y}=e;if(o(n||""),l(s||{}),d(r),u&&f===JSON.stringify(y)){if(p===JSON.stringify(c))return;g(JSON.stringify(c)),"string"==typeof c?fetch(c).then(e=>e.json()).then(e=>{u?.setConfig(e)}):c&&u.setConfig(c)}else m(JSON.stringify(y)),u?.destroy(),(0,i.T)(t.current,{config:c,...y}).then(e=>{h(e),"function"==typeof a&&a(e)})},[e]),(0,r.useEffect)(()=>()=>{u?.destroy()},[]),(0,s.jsx)("div",{ref:t,className:n,style:a,"data-height":c})}var l=n("1858"),c=n("3262"),d=n("1705"),u=n("7645"),h=n("8168"),p=n("8228"),g=n("5050");function f(e){let[t,n]=(0,r.useState)(e.js),[o,i]=(0,r.useState)(e.ts),[a,l]=(0,r.useState)(e.react),[f,m]=(0,r.useState)(e.vue),[y,v]=(0,r.useState)(e.svelte),b="3.7rem",[j,w]=(0,r.useState)(!0),[x,S]=(0,r.useState)(b),C=(0,r.useRef)(null),E=()=>{setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${b})`)},5),setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${b})`)},255)};return(0,r.useEffect)(()=>{if(c.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};n(e(t,"js")),i(e(o,"ts")),l(e(a,"jsx")),m(e(f,"html")),v(e(y,"html"))}},[]),(0,s.jsxs)("details",{className:`alert alert--info ${g.Z.details} ${p.Z.details}`,"data-collapsed":j,style:{height:j?b:x,overflow:"hidden",willChange:"height",transition:`height ${j?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,s.jsx)("summary",{onClick:()=>{w(!j),E()},children:"show code"}),(0,s.jsx)("div",{ref:C,style:{display:"block",overflow:"hidden"},children:(0,s.jsx)("div",{className:g.Z.collapsibleContent,children:(0,s.jsxs)(h.Z,{groupId:"sdk-code",children:[(0,s.jsx)(u.Z,{value:"js",label:"JS",attributes:{onMouseDown:E},children:(0,s.jsx)(d.Z,{language:"js",children:t})}),(0,s.jsx)(u.Z,{value:"ts",label:"TS",attributes:{onMouseDown:E},children:(0,s.jsx)(d.Z,{language:"ts",children:o})}),(0,s.jsx)(u.Z,{value:"react",label:"React",attributes:{onMouseDown:E},children:(0,s.jsx)(d.Z,{language:"jsx",children:a})}),(0,s.jsx)(u.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:E},children:(0,s.jsx)(d.Z,{language:"html",children:f})}),(0,s.jsx)(u.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:E},children:(0,s.jsx)(d.Z,{language:"html",children:y})})]})})})]})}function m(e){let{className:t,style:n,showCode:r,height:i,...c}=e,{colorMode:d}=(0,o.I)(),u=e=>JSON.stringify(e,null,2),h=`
import { createPlayground } from 'livecodes';
const options = ${u(c)};
createPlayground('#container', options);
`.trimStart(),p=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${u(c)};
createPlayground('#container', options);
`.trimStart(),g=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${u(c)};
return (