Localization
KeyboardKit supports 60+ locales.
๐Flexible localization support is an important part of a software keyboard, and should make it possible to localize the entire keyboard.
KeyboardKit defines keyboard-specific languages, where each has localized strings, assets, and locale-specific information. KeyboardKit also extends the native Locale
with additional capabilities.
KeyboardKit Pro unlocks localized keyboards and services for all locales in your license. Information about Pro features can be found at the end of this article.
Supported locales
KeyboardKit supports 61 locales:
๐ฆ๐ฑ ๐ฆ๐ช ๐ฆ๐ฒ ๐ง๐พ ๐ง๐ฌ ๐ฆ๐ฉ ๐ณ๏ธ ๐ญ๐ท ๐จ๐ฟ ๐ฉ๐ฐ ๐ณ๐ฑ ๐ง๐ช ๐บ๐ธ ๐ฌ๐ง ๐บ๐ธ ๐ช๐ช ๐ซ๐ด ๐ต๐ญ ๐ซ๐ฎ ๐ซ๐ท ๐ง๐ช ๐จ๐ญ ๐ฌ๐ช ๐ฉ๐ช ๐ฆ๐น ๐จ๐ญ ๐ฌ๐ท ๐บ๐ธ ๐ฎ๐ฑ ๐ญ๐บ ๐ฎ๐ธ ๐ฎ๐ฉ ๐ฎ๐ช ๐ฎ๐น ๐ฐ๐ฟ ๐น๐ฏ ๐น๐ฏ ๐น๐ฏ ๐ฑ๐ป ๐ฑ๐น ๐ฒ๐ฐ ๐ฒ๐พ ๐ฒ๐น ๐ฒ๐ณ ๐ณ๐ด ๐ฎ๐ท ๐ต๐ฑ ๐ต๐น ๐ง๐ท ๐ท๐ด ๐ท๐บ ๐ท๐ธ ๐ท๐ธ ๐ธ๐ฐ ๐ธ๐ฎ ๐ช๐ธ ๐ฐ๐ช ๐ธ๐ช ๐น๐ท ๐บ๐ฆ ๐บ๐ฟ
Each keyboard locale refers to a native Locale
and has additional keyboard-specific information, as well as localized assets and strings that can be translated with the KKL10n
enum.
Locale extensions
KeyboardKit extends the native Locale
with more functionality.
Direction info
KeyboardKit lets you get the line and character direction of a locale:
let english = KeyboardLocale.english.locale
let persian = KeyboardLocale.persian.locale
let swedish = KeyboardLocale.swedish.locale
english.isLeftToRight // true
english.isRightToLeft // false
persian.isLeftToRight // false
persian.isRightToLeft // true
swedish.isTopToBottom // false
english.lineDirection // .leftToRight
persian.lineDirection // .rightToLeft
swedish.lineDirection // .leftToRight
Flag info
KeyboardKit lets you get the flag of a locale:
english.locale.flag // ๐บ๐ธ
persian.locale.flag // ๐ฎ๐ท
swedish.flag // ๐ธ๐ช
Localized name
KeyboardKit lets you get and use the localized names of a locale:
english.localizedName // English (United States)
swedish.localizedName(in: english) // Swedish (Sweden)
swedish.localizedName(in: swedish) // Svenska (Sverige)
Sorting
KeyboardKit also provide convenient Locale collection sorted extensions.
How to get the current keyboard locale
You can get the current locale and all available locales with KeyboardContext
โs .locale
and .locales
.
These properties return raw Locale
s, since a keyboard extension is not limited to the KeyboardLocale
model. The context also has optional, KeyboardLocale
-specific functions.
How to change keyboard locale
You can change the keyboard locale for a KeyboardContext
by setting locale
to a new locale, or use the convenience functions that support KeyboardLocale
.
If the context locales
has multiple values, you can switch locale using selectNextLocale()
or using a LocaleContextMenu
view that lets the user select a locale.
Setting the locale will update the controllerโs primaryLanguage
, which controls things like spellchecking and text direction. It will also set the display name in the system keyboard switcher.
LTR and RTL locales
KeyboardKit supports LTR (Left-To-Right) and RTL (Right-To-Left) locales.
You donโt need to configure your keyboard to support RTL. Just change the keyboard locale as explained above, and KeyboardKit will automatically adjust the text direction.
How to translate localized content
Each KeyboardLocale
has a localized strings file in Resources/<id>.lproj
.
Localized strings can be translated using the KKL10n
enum. For instance, this translates the text for the numeric button key for the current locale:
let translation = KKL10n.keyboardTypeNumeric.text
Besides localized strings, you can get flags for a keyboard locales, using the flag
property. You can also use the contextโs localePresentationLocale
property to set how locales are displayed.
๐ Pro features
KeyboardKit Pro unlocks a localized InputSet
, KeyboardLayoutProvider
and CalloutActionProvider
for every KeyboardLocale
that the license unlocks.
This means that KeyboardKit Pro can create fully localized SystemKeyboard
for all supported locales.
Documentation
The information on this page is shortened to be easier to overview. For more information about this feature, code samples, etc., please see the online documentation.