# Setting locales (thread and invariant)

**URL:** <https://forums.swift.org/t/setting-locales-thread-and-invariant/29789>\
**Category:** Using Swift\
**Created:** [October 13, 2019, 5:19pm UTC](https://forums.swift.org/t/setting-locales-thread-and-invariant/29789 "2019-10-13T17:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatrickA](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PatrickA](https://forums.swift.org/u/PatrickA)\
**Post date:** [October 13, 2019, 5:19pm UTC](https://forums.swift.org/t/setting-locales-thread-and-invariant/29789/1 "2019-10-13T17:19:51Z")

</div>

Two questions coming from the .NET World.

I understand that there is no way in Swift to change the thread's current locale (in .NET there is a way to change the thread's current "culture") and that only the device's current locale can be changed. Apparently, the device's current locale may not be changed programmatically. Is that right? If so, how will Swift running on a server handle requests from various clients whose locales may be different?

Is there such a concept as an "invariant" locale (to avoid notably surprizes with a Turkish device for instance). An invariant locale which could be used, for instance, with

> String.range(of: pattern, options:.regularExpression, locale: locale)

?

(If there is no equivalent concept, I suppose one could use the English US locale... Although on .NET, invariant locale and US locale don't behave to same way when using toUpper() for µ U+00B5 and ı U+0131...)

---

<div class="post-metadata">

**Author:** ![DeFrenZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/defrenz/32/827_2.png) [@DeFrenZ](https://forums.swift.org/u/DeFrenZ)\
**Post date:** [October 13, 2019, 5:27pm UTC](https://forums.swift.org/t/setting-locales-thread-and-invariant/29789/2 "2019-10-13T17:27:34Z")

</div>

Usually objects that make use of a `Locale` to do their computations accept injecting one, which by default will be the machine's.

So yes, you can specify "invariant" locales

---

<div class="post-metadata">

**Author:** ![eskimo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/eskimo/32/13558_2.png) [@eskimo](https://forums.swift.org/u/eskimo)\
**Post date:** [October 14, 2019, 8:33am UTC](https://forums.swift.org/t/setting-locales-thread-and-invariant/29789/3 "2019-10-14T08:33:30Z")

</div>

> Is there such a concept as an "invariant" locale

I believe the droid you’re looking for here is the `en_US_POSIX` locale.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple
