Sp-dev-docs: How does the localization work?

Created on 25 Aug 2016  路  6Comments  路  Source: SharePoint/sp-dev-docs

the folder "loc" contains an en-us.js, and mystrings.d.ts
This is not documented anywhere as far as I can tell. And why is en-us.js a JS file, not a TS file? It looks quite complicated.

tracked

Most helpful comment

Correct. The API in config.json which specifies localizedResources is designed to be flexible enough to load any JS resource for the current culture. However, that means these resources need to be standalone JS bundles (hence the define() stuff).

We're working on improvements to the localization story that would effectively let you add TypeScript, RESX, or JSON files in src/loc, and we would convert these to standalone bundles (e.g. webpack) for you.

[We're also working on allowing you to embed a specific type of localized resource -- strings -- directly into your code bundles. This would mean we would be creating files like myWebPart.bundle.en_us.js, myWebPart.bundle.fr_fr.js instead of myWebPart.bundle.js, myWebPart-strings-en_us.js, myWebPart-strings-fr_fr.js.]

All 6 comments

Correct. The API in config.json which specifies localizedResources is designed to be flexible enough to load any JS resource for the current culture. However, that means these resources need to be standalone JS bundles (hence the define() stuff).

We're working on improvements to the localization story that would effectively let you add TypeScript, RESX, or JSON files in src/loc, and we would convert these to standalone bundles (e.g. webpack) for you.

[We're also working on allowing you to embed a specific type of localized resource -- strings -- directly into your code bundles. This would mean we would be creating files like myWebPart.bundle.en_us.js, myWebPart.bundle.fr_fr.js instead of myWebPart.bundle.js, myWebPart-strings-en_us.js, myWebPart-strings-fr_fr.js.]

Cool. Those improvements look great.

We're going to leave this issue open, as this is a pending item to fix on an upcoming drop.

Let's say I used localizedResources in a webpart/component, let's call it A. Now I include that in another project, let's call it B, through package.json/npm install. As of now, I don't see how to include these without having Module not found: Error: Can't resolve ... errors while building B, unless I add A localizedResources to B localizedResources, ex: through node_modules/project_A/lib/loc/{locale}.js.

Is there a way to do that that I'm just not seeing?

Hi,

We have documented how localization works here

I'm closing this issue for now. Please open a separate bug if you're running into issues with localization.

Thanks!

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

Was this page helpful?
0 / 5 - 0 ratings