Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
feat(ssr): add translation from server in SSR
Browse files Browse the repository at this point in the history
feat(ssr): add translation from server in SSR
  • Loading branch information
Metnew committed Sep 10, 2017
1 parent 92312a5 commit 403ae4e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server/ssr/IndexHTMLComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ type args = {
App: string,
initialState: Object,
assets: Object,
faviconsAssets: Object
faviconsAssets: Object,
translation: Object
}
// renderToString
const DLLScripts =
Expand All @@ -20,16 +21,18 @@ const IndexHTMLComponent = ({
App,
initialState,
assets,
faviconsAssets
faviconsAssets,
translation
}: args) => {
const stringifiedState: string = JSON.stringify(initialState)
const stringifiedTranslation: string = JSON.stringify(translation)
const safeStringifiedState: string = stringifiedState.replace(/</g, '\\u003c')

const createBody = () => {
const html = `
<div id="app">${App}</div>
<script>window.__INITIAL_STATE__ = ${safeStringifiedState}</script>
<script>window.__I18N__ = ${safeStringifiedState}</script>
<script>window.__I18N__ = ${stringifiedTranslation}</script>
${DLLScripts}
${Object.keys(assets)
.filter(bundleName => assets[bundleName].js)
Expand Down

0 comments on commit 403ae4e

Please sign in to comment.