question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Where do you actually store your translation object?

See original GitHub issue

Has anyone used this for a real large project that might need to support multiple different languages? I find it hard to believe that having all your translations inline in app.js is sustainable on a large scale. I would like to separate my translation files by component for maximum portability and modularization (I understand the overhead this adds to the task of translating), but I’m not sure how best to do that with this package.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
ozluycommented, Jan 19, 2017

Hi @beaulm,

Create a i18n folder to and put en.js, tr.js and index.js inside of it

en.js

 export const en = {
    application: {
      name: 'Name Surname',
      company: 'Company',
      blog: 'Website',
      location: 'Location',
      email: 'Email Address',
      created_at: 'Account Create Date',
      desc:'%{name} on Github'
    },
    date: {
      long: 'MMMM Do, YYYY'
    }
    
  };

tr.js

 export const tr = {
    application: {
      name: 'Ad Soyad',
      company: 'Şirket',
      blog: 'Web Sayfası',
      location: 'Lokasyon',
      email: 'Email',
      created_at: 'Hesap Açılış Tarihi',
      desc:'Github\'ta %{name}'
    },
    date: {
      long: 'DD.MM.YYYY'
    }
  };

index.js

import { tr } from './tr';
import { en } from './en';
export const translationsObject = {
    tr: tr,
    en: en
};

then import index.js same as I did below(line with emojis) in your store file

store.js

import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from '../reducers';
import reduxImmutableStateInvariant from 'redux-immutable-state-invariant';
import thunk from 'redux-thunk';
import { loadTranslations, setLocale, syncTranslationWithStore } from 'react-redux-i18n';
import { translationsObject } from '../i18n/index.js';//⛄🌨❄ 

export default function configureStore(initialState) {

  const finalCreateStore = compose(
    applyMiddleware(thunk, reduxImmutableStateInvariant()),
    window.devToolsExtension ? window.devToolsExtension() : f => f

  )(createStore);


  const store = finalCreateStore(rootReducer, initialState);
  if (module.hot) {
    module.hot.accept('../reducers', () =>
      store.replaceReducer(require('../reducers'))
    );
  }
  syncTranslationWithStore(store);
  store.dispatch(loadTranslations(translationsObject));
  localStorage.getItem('appLang') ? null : localStorage.setItem('appLang', 'tr');
  store.dispatch(setLocale(localStorage.getItem('appLang')));
  return store;
}


Hope thats what you are looking for…

Happy Hacking 👍

0reactions
flo-schcommented, Feb 4, 2018

Can we close this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transformations - Translating On The Coordinate Plane
This brief video explains how you can quickly figure out how to translate an object by adding or subtracting to the original coordinates....
Read more >
What is Translation in Math? - Definition, Examples, & Terms
When you are performing a translation, the initial object is called the pre-image, and the object after the translation is called the image....
Read more >
How To Use Translation Keys To Create Internationalized ...
Keeping it local ... The locale file stores values for translation keys and an individual locale file is created for each language on...
Read more >
Entity Translation API - Drupal
In any moment a translation object can be instantiated from the original object or another translation object through the EntityInterface:: ...
Read more >
Translation of objects in computer graphics - GeeksforGeeks
Some of basic objects along with their translation can be drawn as: Point Translation P(X, Y) : Here we only translate the x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found