Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate constant files #45

Open
gautamvij opened this issue Aug 19, 2017 · 2 comments
Open

Translate constant files #45

gautamvij opened this issue Aug 19, 2017 · 2 comments

Comments

@gautamvij
Copy link

Hi.
I have this use case of translating config files which are outside the scope of react. Though currently, I am passing the context.t to these constant .js files from the components and getting the translated labels.

Is there a better way of doing it ?

PS: awesome package !

@gautamvij gautamvij changed the title Support Translate constant files Aug 19, 2017
@fabiulous
Copy link
Contributor

+1

I have a middleware to show notifications and this is outside of react control.

import Notifications from "react-notification-system-redux"

import {
  PROFILE_UPDATE_PASSWORD_SUCCESS,
  PROFILE_UPDATE_CONTACT_SUCCESS,
} from "../constants"

export default function notificationMiddleware(store) {
  return next => action => {
    let options
    let level

    switch (action.type) {
      case PROFILE_UPDATE_PASSWORD_SUCCESS:
        options = {
          title: "Success!",
          message: "Password has been successfully changed.",
          position: "tr",
        }
        level = "success"
        break
      case PROFILE_UPDATE_CONTACT_SUCCESS:
        options = {
          title: "Success!",
          message: "Contact details have been successfully modified.",
          position: "tr",
        }
        level = "success"
        break
      default:
        options = null
    }

    if (options) {
      store.dispatch(Notifications.show(options, level))
    }
    next(action)
  }
}

Any clever way to translate those messages, and keeping this as a middleware?

@fabiulous
Copy link
Contributor

In middleware I was able to access translate function with:

import { getTranslateFunction } from "redux-i18n"

export default function notificationMiddleware({ dispatch, getState }) {
  return next => action => {
    const { i18nState } = getState()
    const translate = getTranslateFunction(i18nState.translations, i18nState.lang, "en")
(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants