@@ -18,12 +18,24 @@ import dayjs from 'dayjs';
1818import languageRules from 'constants/languageRules' ;
1919import fireEvent from 'helpers/fireEvent' ;
2020import Events from 'constants/events' ;
21+ import getAvailableLanguages from './getAvailableLanguages' ;
22+ import textToolNames from 'constants/textToolNames' ;
23+ import localStorageManager from 'helpers/localStorageManager' ;
24+ import { getInstanceID } from 'helpers/getRootNode' ;
25+ import setToolStyles from 'helpers/setToolStyles' ;
2126
2227let pendingLanguageTimeout ;
2328export default ( store ) => async ( language ) => {
2429 if ( pendingLanguageTimeout ) {
2530 clearTimeout ( pendingLanguageTimeout ) ;
2631 }
32+
33+ const availableLanguages = getAvailableLanguages ( ) ;
34+ if ( ! availableLanguages . includes ( language ) ) {
35+ console . warn ( `Language with ISO code "${ language } " is not supported.` ) ;
36+ return ;
37+ }
38+
2739 await new Promise ( ( resolve ) => {
2840 pendingLanguageTimeout = setTimeout ( async ( ) => {
2941 let languageObj = null ;
@@ -49,6 +61,9 @@ export default (store) => async (language) => {
4961 const pendingLanguagePromise = i18next . changeLanguage ( language ) ;
5062 setDatePickerLocale ( pendingLanguagePromise , language ) ;
5163 await pendingLanguagePromise ;
64+
65+ updateTextToolDefaults ( ) ;
66+
5267 fireEvent ( Events [ 'LANGUAGE_CHANGED' ] , languageEventObject ) ;
5368 }
5469 resolve ( ) ;
@@ -73,3 +88,38 @@ const setDatePickerLocale = (i18nextPromise, language) => {
7388 } ) ;
7489 } ) ;
7590} ;
91+
92+ const applyTextToolDirectionalDefaults = ( toolName , directionSpecificStyles ) => {
93+ const isRTL = i18next ?. dir ( ) === 'rtl' ;
94+ const rtlDefaults = directionSpecificStyles || { } ;
95+
96+ const font = isRTL ? rtlDefaults . Font || 'Noto Sans Arabic' : 'Helvetica' ;
97+ const textAlign = isRTL ? rtlDefaults . TextAlign || 'right' : 'left' ;
98+
99+ setToolStyles ( toolName , 'Font' , font ) ;
100+ setToolStyles ( toolName , 'TextAlign' , textAlign ) ;
101+ } ;
102+
103+ const updateTextToolDefaults = ( ) => {
104+ const { ToolNames } = window . Core . Tools ;
105+
106+ for ( const toolKey of textToolNames ) {
107+ const toolName = ToolNames [ toolKey ] ;
108+ let directionSpecificStyles = null ;
109+
110+ if ( localStorageManager . isLocalStorageEnabled ( ) ) {
111+ const instanceId = getInstanceID ( ) ;
112+ directionSpecificStyles = JSON . parse ( localStorageManager . getItemSynchronous ( `${ instanceId } -toolData-${ toolName } -${ i18next . dir ( ) } ` ) ) ;
113+ }
114+ if ( directionSpecificStyles && ( directionSpecificStyles . Font || directionSpecificStyles . TextAlign ) ) {
115+ if ( directionSpecificStyles . Font ) {
116+ setToolStyles ( toolName , 'Font' , directionSpecificStyles . Font ) ;
117+ }
118+ if ( directionSpecificStyles . TextAlign ) {
119+ setToolStyles ( toolName , 'TextAlign' , directionSpecificStyles . TextAlign ) ;
120+ }
121+ } else {
122+ applyTextToolDirectionalDefaults ( toolName ) ;
123+ }
124+ }
125+ } ;
0 commit comments