isRTL property of UserSettings API in PCF Control to Determine Language within Dynamics 365 CRM

Sending
User Review
0 (0 votes)

Introduction

As we know, PCF control can be run in multiple languages. Each language has a script to be written and it will be written with a direction. Some languages are written in the left-to-right direction, whereas some are written in the right-to-left. For example, English language script is written left to write, whereas Arabic language script is written in the right-to-left direction.

In PCF control, when the user interface language is set to Arabic, then the direction of the user interface will be switched in the right-to-left direction. To handle this situation in PCF control, we can use userSettings API of Power Apps. This API helps us to identify whether the user interface language is written in right-to-left or not and makes it easy to change the user interface on the basis of the language.

Please find the code below:

//function that returns the value of isRTL property
isRTL(context: ComponentFramework.Context<IInputs>) {
return context.userSettings.isRTL;
}

For example, we have field type PCF control in which the field returns the value of isRTL property. We have set the user interface language is English, that’s why isRTL returns false as seen in the screenshot below.

isRTL property of UserSettings API in PCF Control

In the below example, we have set the Arabic language as a user interface language, hence isRTL shows true.

isRTL property of UserSettings API in PCF Control

Conclusion

By using UserSettings API, we can easily get the direction in which the language is to be written and make the required changes in the user interface.