Signature
Parameters
Optional BCP 47 locale tag (e.g.
'ja', 'ar', 'zh-Hant'). If omitted, Pretext resets to the runtime’s default locale.What it does
setLocale() retargets the hoisted word segmenter used internally by prepare() and prepareWithSegments(). All subsequent calls to those functions will use the new locale for Intl.Segmenter-based word segmentation.
It also calls clearCache() internally, so the old segment metrics and grapheme caches are discarded. This ensures stale measurements from a previous locale do not bleed into new results.
Important: existing handles are not affected
Setting a new locale does not mutate anyPreparedText or PreparedTextWithSegments handles that were created before the call. Those handles remain valid and continue to produce correct layout results for the font and locale they were prepared under.
When to call
CallsetLocale() once, before your first prepare() call in a session, when you want a specific locale rather than the runtime default:
Relationship to clearCache()
setLocale() calls clearCache() internally when the locale changes. You do not need to call clearCache() separately after setLocale().