Soya Next
  • Introduction
  • Packages
    • soya-next
    • soya-next-cli
    • soya-next-scripts
    • soya-next-server
  • Getting Started
    • Setup
    • Directory Structure
    • Creating an App
    • Build the App for Production
  • User Guide
    • Analyzing Dependencies
    • Configure Redux Store
    • Custom Babel Configuration
    • Custom Document
    • Custom Marlint Configuration
    • Custom Routing
    • Typescript Configuration
    • Universal Environment Configuration
  • Migration Guide
    • 0.4.x to 0.5.x
  • API Reference
    • applyReducers([reducers])
    • createPage([...connectArgs])(Page, [reducers])
    • createRouter(app, [options])
    • withLocale
    • LocaleLink
  • Examples
    • Apollo
    • Authentication
    • CSS Modules
    • CSS Modules with SCSS
    • Custom Routes
    • Internationalization
    • Internationalization with Redux
    • Redirection
    • TodoMVC
  • License
Powered by GitBook
On this page
  • Usage
  • How It Works
  1. Examples

Internationalization

PreviousCustom RoutesNextInternationalization with Redux

Last updated 7 years ago

Usage

Clone this repository:

git clone https://github.com/traveloka/soya-next.git
cd soya-next/examples/i18n

Then, install and run it:

npm install
npm start

Open in your browser.

How It Works

This example uses to enable internationalization.

To use it, create a configuration file at config/default.json with the following:

{
  "defaultLocale": "id-id",
  "siteLocales": [
    "id-id",
    "en-id"
  ]
}

To access locale, default locale, and site locales within your application, you need to provide them into every page using createPage() as follows:

import { createPage } from 'soya-next';

const Page = ({
  locale,
  defaultLocale,
  siteLocales,
}) => {};

Page.getIntialProps = ({
  locale,
  defaultLocale,
  siteLocales,
}) => {};

export default createPage()(Page);

Now, you can access them in your component as well using withLocale:

import { withLocale } from 'soya-next/i18n';

export default withLocale(({ defaultLocale, locale, siteLocales }) => {});
http://localhost:3000
express middleware