Implemeted: i18n for centralized use (#134) #145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #134
Steps to verify --
Description -
- Unable to access the app files in the pulgin:
I tried accessing the app files in the plugin but only able to access the node-modules folder files.
How i tried to accessing it - by requiring all the files using require.context and giving the path of the apps location.
Tried to find different ways how it can be done but found nothing.
- Shifted i18n logic to dxp-components in index.ts. This is because:
When taking localeMessages from the app as plugin options and when passing it in context to another location (lets say i18n.ts) and importing the context in the file error occurs of contex.localeMessages used before initialization this is beacause when importing this file from the index.ts the file (i18n.ts) runs first and then the rest logic (of creating the context and assigning localeMessages) in index.ts.
- Removed the function (to load localeMessages from the locales folder and creating an object):
The above function just creates an object of JSONs present in the locales file like - { en: { }, es: {} }
Now with the new approach i am just exporting this JSONs from locales folder by creating index.ts and exporting the required object { en: { } } by importing the JSONs in the index.ts
Now importing this object (exported from the locales/index.ts) and passing it dxp options.
Note - for importing JSONs in typescript added "resolveJsonModule": true configuration in ts config.
- How process and require can be used in the ts files of dxp:
by declaring them like :-
declare var process: any;
in the file
Here we are telling the TypeScript compiler that there is already a variable named process with the type any. This is useful when you have variables introduced by sources that the compiler is not be aware of.