Internationalisation - I18n
This section is about how we can define localised content in the context of the Miam SDK.
By default, Mealz supports two languages: English and French
Override Mealz SDK values
Strings
To override Mealz default strings, you'll need to create a Localizable.strings file (or add to your existing file).
- XCProject/XCWorkspace
- Swift Package
The Localizable.strings should be placed in a Localization folder.
From there, on the right hand side of the XCode editor under Identity and Type, you check the language you wish to customize.
The Localizable.strings should be placed in a Resources folder, then nested in a COUNTRY_CODE.lproj folder.
For example, to set French, you would have a file structure like this: Resources/fr.lproj/Localizable.
From there, you'll just need to be sure that the Resources folder is listed in the target of your Package.swift.
For example:
targets: [
.target(
name: "MiamNeutraliOSFramework",
dependencies: [
.product(name: "MiamIOSFramework", package: "miam-sdk")
],
// make sure resources are here
resources: [
.process("Resources"),
]),
First thing is to create a new entry in your Localizable.strings, to provide your localisation:
// Localizable.strings
"com_miam_details_add_all_products" = "Add recipe to basket";
Plurals
To override Mealz default plurals, you'll need to create a Localizable.stringsdict file (or add to your existing file).
- XCProject/XCWorkspace
- Swift Package
The Localizable.stringsdict should be placed in a Localization folder.
From there, on the right hand side of the XCode editor under Identity and Type, you check the language you wish to customize.
The Localizable.stringsdict should be placed in a Resources folder, then nested in a COUNTRY_CODE.lproj folder.
For example, to set French, you would have a file structure like this: Resources/fr.lproj/Localizable.
From there, you'll just need to be sure that the Resources folder is listed in the target of your Package.swift.
For example:
targets: [
.target(
name: "MiamNeutraliOSFramework",
dependencies: [
.product(name: "MiamIOSFramework", package: "miam-sdk")
],
// make sure resources are here
resources: [
.process("Resources"),
]),
First thing is to create a new entry in your Localizable.stringsdict, to provide your localisation:
<!--Localizable.stringsdict -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com_miam_basket_product</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@VARIABLE@</string>
<key>VARIABLE</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>f</string>
<key>one</key>
<string>%d item</string>
<key>other</key>
<string>%d items</string>
</dict>
</dict>
</dict>
</plist>
Register
Then, as Moko is reading localisations from a Bundle, that by default is the Mealz SDK's bundle, you need to register your app's bundle on the I18nResolver before consuming any override resources.
I18nResolver.shared.registerAppBundle(bundle: Bundle.main)
If you are using Swift Package, you might want to export your Bundle to be used by the Mealz SDK.
You can add this code to your PackageName File.
For example, our package is MealzUIiOSSDK so:
// file MealzUIiOSSDKBundle.swift
public struct MealzUIiOSSDKBundle {
public init() {}
public static var bundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle.main
#endif
}
}
Then in our MealzManager in a separate package, we call:
I18nResolver.shared.registerAppBundle(bundle: MealzUIiOSSDKBundle.bundle)
After that, consuming com_miam_i18n_recipe_add on iOS, should display Add recipe to basket instead of Add ingredients.
When consuming com_miam_basket_product, you should see 1 item & 2 items instead of 1 article & 2 articles.