0

I want to add multiple languages to my spfx web part.

Now I want to import some interfaces to my mystrings.d.ts declaration file. But when I do that it breaks the definition and I get a lot of errors like:

enter image description here

My question is if it's possible to import interfaces to my declaration file for my strings so that i don't have to write these definitions on my own?

  • import some interfaces to my "mystrings.d.ts" what do you mean by this? It is confusing. Are you using this interface in other TSX/JSX file? – ThinkB4Code Oct 14 at 16:13
1

Please check the below steps for adding multiple language in SPFX webparts:

  1. Within "loc" folder you will see a file named "mystrings.d.ts". At first add property here like below:
declare interface ITestWebPartStrings {
  WebpartTitle: string;
}
  1. There is a file for english language named "en-us.js". If you want to add another language you have to create another file. For example if you want to add Norwegian language then you have to create "nb-NO.js" file.
  2. After that add the property in "nb-NO.js" file for Norwegian language. And for english language add property within "en-us.js" file as like below:
define([], function() {
    return {
        "WebpartTitle": "YourTitle",
    }
});
  1. Now you have to import in your file.
import * as strings from 'TestWebPartStrings';
  1. Now you can show "WebpartTitle" using "strings.WebpartTitle". This is the process to add multiple language.
let wpTitle = strings.WebpartTitle;

If the answer is helpful, please upvote and mark as accepted.

  • 1
    First, thaks a lot. I think i didn't described my problem exactly. I know how to add multiple languages to my project. The probblem is that i e.g. use the fabric ui calendar and want to set the calendar strings into my language files. therefore i added the "ICalendarStrings" into my mystrings.d.ts file. But therefore i have to import the interface. But then i get the errors from above. – Thomas Mueller Oct 15 at 6:55
  • You are welcome. Now your problem is clear. – Md. Nizam Uddin Mahmud Oct 15 at 7:20
0

If you want to localize your SharePoint Framework web-part to use it for different languages then you can create multiple javascript files for each languages which will have definitions for properties of your web-part.

Follow below official documentation by Microsoft for the same:

Localize SharePoint Framework client-side web parts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.