getLocaleDirection method
T039: Gets the text direction for a locale. Checks custom locale directions first, then falls back to predefined RTL language codes. Returns 'rtl' for right-to-left languages, 'ltr' for left-to-right.
Implementation
Future<String> getLocaleDirection(String locale) async {
final state = await _stateStore.load(
config: config,
projectRootPath: projectRootPath,
);
// Check if this is a custom locale with configured direction
if (state.customLocaleDirections.containsKey(locale)) {
return state.customLocaleDirections[locale]!;
}
// Check if it's a predefined RTL language
final languageCode = getLanguageCode(locale);
const rtlLanguages = {
'ar', // Arabic
'fa', // Farsi/Persian
'he', // Hebrew
'ku', // Kurdish
'ps', // Pashto
'sd', // Sindhi
'ur', // Urdu
'yi', // Yiddish
};
if (rtlLanguages.contains(languageCode)) {
return 'rtl';
}
return 'ltr'; // Default to LTR
}