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

how to load multiple JSON files instead of single JSON file of a single language #46

Closed
kabiragarwal opened this issue Feb 20, 2018 · 2 comments

Comments

@kabiragarwal
Copy link

Hi there,

Thanks for providing the react-intl-universal library. I have used it easily without any issue.

but currently language local data is not in a single file but on multiple JSON files in the local folder. so I have to load all the JSON files from the local folder and then display the data. I am considering only one language currently.

Thanks in advance.

@cwtuan
Copy link
Collaborator

cwtuan commented Apr 3, 2018

@cwtuan cwtuan closed this as completed Apr 3, 2018
@lsiric
Copy link
Contributor

lsiric commented Apr 18, 2018

Hi @cwtuan, thanks for the fix. Having language local data in multiple files is a great, and a must-have feature for any non-trivial application.

The issue I'm having is with the standard Object.assign function which is used in the load function implementation: it overrides existing defined locales.

Example:

ComponentOne has locales defined in the same folder, in the file localesOne.json:

{
  "en-US": {
    "hello": "hello from component one" 
  }
}

ComponentTwo has locales defined in the same folder, in the file localesTwo.json:

{
  "en-US": {
    "hello": "hello from component two" 
  }
}

load function is used in each of the respective components:

// componentOne
intl.load({
  'en-US': require('localesOne.json');
});
// componentTwo
intl.load({
  'en-US': require('localesTwo.json');
});

The issue occurs when the load function is invoked for the second time, it overrides the entire en-US locale which was already loaded. This means that once the locales for componentTwo are loaded, locales for componentOne are non existent any more (and vice versa).

The solution for this could be using deep merge, thus preserving the old values within the object being extended.

This way the load method could be leveraged in each of the smart components, and managing .json files throughout the application woud be nice and easy.

Is this something that could potentially be implemented?

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

3 participants