Skip to content

Commit

Permalink
🌐 - Added Arabic & English localization for the Apple Watch app (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
guytepper authored Oct 20, 2021
1 parent 3a65080 commit 188fa3e
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 90 deletions.
33 changes: 26 additions & 7 deletions ios/BetterRail.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
C17FA4C12709EFBB003797D9 /* WatchBetterRail Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = C17FA4C02709EFBB003797D9 /* WatchBetterRail Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
C17FA4D32709EFBC003797D9 /* WatchBetterRail.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = C17FA4B72709EFBB003797D9 /* WatchBetterRail.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
C183229A270DF49100A44771 /* StationImageBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1832299270DF49100A44771 /* StationImageBackground.swift */; };
C1B3FCF3271EEFFA000F33AE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C1B3FCF5271EEFFA000F33AE /* Localizable.strings */; };
C1E62DD8270EE24C0067F262 /* StationListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E62DD7270EE24C0067F262 /* StationListItem.swift */; };
C1E62DDA270EE2690067F262 /* TrainStopListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E62DD9270EE2690067F262 /* TrainStopListItem.swift */; };
C1E62DDC270EE28B0067F262 /* TrainExchangeListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E62DDB270EE28B0067F262 /* TrainExchangeListItem.swift */; };
Expand Down Expand Up @@ -135,6 +136,9 @@
C17FA4C02709EFBB003797D9 /* WatchBetterRail Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "WatchBetterRail Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
C17FA4D02709EFBC003797D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C1832299270DF49100A44771 /* StationImageBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationImageBackground.swift; sourceTree = "<group>"; };
C1B3FCF4271EEFFA000F33AE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
C1B3FCF6271EEFFD000F33AE /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
C1B3FCF7271F25AA000F33AE /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };
C1E62DD7270EE24C0067F262 /* StationListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationListItem.swift; sourceTree = "<group>"; };
C1E62DD9270EE2690067F262 /* TrainStopListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrainStopListItem.swift; sourceTree = "<group>"; };
C1E62DDB270EE28B0067F262 /* TrainExchangeListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrainExchangeListItem.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -306,6 +310,7 @@
C1F61BFC2709F08200CD3D44 /* ViewModels */,
C1F61C072709F08200CD3D44 /* Models */,
C1F61C0C2709F08200CD3D44 /* stationsData.json */,
C1B3FCF5271EEFFA000F33AE /* Localizable.strings */,
C1F61C062709F08200CD3D44 /* WatchBetterRail.swift */,
C1F61C102709F08200CD3D44 /* Utilities.swift */,
C17FA4D02709EFBC003797D9 /* Info.plist */,
Expand Down Expand Up @@ -491,7 +496,7 @@
};
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "BetterRail" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = he;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
he,
Expand Down Expand Up @@ -551,6 +556,7 @@
buildActionMask = 2147483647;
files = (
C1F61C1F2709F08200CD3D44 /* stationsData.json in Resources */,
C1B3FCF3271EEFFA000F33AE /* Localizable.strings in Resources */,
C1F29D28270B2D31009B953E /* Heebo-Bold.otf in Resources */,
C1F61C252709F09B00CD3D44 /* Assets.xcassets in Resources */,
C1F29D2C270B2D31009B953E /* Heebo-Medium.otf in Resources */,
Expand Down Expand Up @@ -785,6 +791,19 @@
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C1B3FCF5271EEFFA000F33AE /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
C1B3FCF4271EEFFA000F33AE /* en */,
C1B3FCF6271EEFFD000F33AE /* he */,
C1B3FCF7271F25AA000F33AE /* ar */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
00E356F61AD99517003FC87E /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -837,7 +856,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = UE6BVYPPFX;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = BetterRail/Info.plist;
Expand Down Expand Up @@ -866,7 +885,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = UE6BVYPPFX;
INFOPLIST_FILE = BetterRail/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand Down Expand Up @@ -1015,7 +1034,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = UE6BVYPPFX;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down Expand Up @@ -1052,7 +1071,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = UE6BVYPPFX;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down Expand Up @@ -1083,7 +1102,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = UE6BVYPPFX;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1118,7 +1137,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = UE6BVYPPFX;
ENABLE_PREVIEWS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "32">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Better Rail">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -73,16 +75,27 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "32">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Better Rail">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,46 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Better Rail">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Better Rail">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17FA4B62709EFBB003797D9"
BuildableName = "WatchBetterRail.app"
BlueprintName = "WatchBetterRail"
ReferencedContainer = "container:BetterRail.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
5 changes: 1 addition & 4 deletions ios/BetterRail/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleDevelopmentRegion</key>
<array>
<string>he</string>
<string>en</string>
</array>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Better Rail</string>
<key>CFBundleExecutable</key>
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ PODS:
- React
- RNWatch (1.0.4):
- React
- ToastHybrid (2.4.0):
- ToastHybrid (2.4.5):
- React
- UMCore (7.1.2)
- UMReactNativeAdapter (6.3.9):
Expand Down Expand Up @@ -694,7 +694,7 @@ SPEC CHECKSUMS:
RNSharedElement: 87baf6d04da5b068f000dd8c953d28a1196999c0
RNSVG: ce9d996113475209013317e48b05c21ee988d42e
RNWatch: 99637948ec9b5c9ec5a41920642594ad5ba07e80
ToastHybrid: c5ad7ee8ac15b41da0b714a1b250b3f3fc7d5fa6
ToastHybrid: 432381039a804a60e142ebaa7af8290e236c288e
UMCore: ce3a4faa010239063b8343895b29a6d97b01069d
UMReactNativeAdapter: d03cefd0e4e4179ab8c490408589f1c8a6c8b785
Yoga: c11abbf5809216c91fcd62f5571078b83d9b6720
Expand Down
3 changes: 2 additions & 1 deletion ios/WatchBetterRail Extension/Models/FavoritesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct FavoriteRoute: Identifiable {

#if DEBUG
let fav = FavoriteRoute(id: 0, origin: stations[2], destination: stations[65])
let fav2 = FavoriteRoute(id: 1, origin: stations[6], destination: stations[8])
#endif

struct FavoritesModel {
Expand Down Expand Up @@ -40,7 +41,7 @@ struct FavoritesModel {

self.routes = favoriteRoutes
#if DEBUG
self.routes = [fav]
self.routes = [fav, fav2]
#endif
}
}
1 change: 1 addition & 0 deletions ios/WatchBetterRail Extension/Models/RouteModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct RouteModel {
/// Today's date, formatted properly for Israel Railways API endpoint
static private var todayDate: String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_us")
dateFormatter.dateFormat = "YYYYMMdd"
return dateFormatter.string(from: Date())
}
Expand Down
52 changes: 33 additions & 19 deletions ios/WatchBetterRail Extension/Models/StationModel.swift
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import Foundation

struct Station: Codable, Hashable, Identifiable {
/// Used for decoding the station name according to the device locale.
let userLocale = getUserLocale()
struct Station: Decodable, Hashable, Identifiable {
let id: String
let name: String
let image: String?
let image: String?

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
id = try values.decode(String.self, forKey: .id)
name = try values.decode(String.self, forKey: CodingKeys(rawValue: userLocale)!)

if (values.contains(.image)) {
image = try values.decode(String.self, forKey: .image)
} else {
image = nil
}
}

enum CodingKeys : String, CodingKey {
case id, image
case name = "hebrew"
case hebrew, arabic, english
}
}
}

var stations: [Station] = load("stationsData.json")

func load<T: Decodable>(_ filename: String) -> T {
let data: Data
let data: Data

guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle.")
guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle.")
}

do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}
do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}

do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}

func getStationById(_ id: String) -> Station? {
Expand Down
29 changes: 21 additions & 8 deletions ios/WatchBetterRail Extension/Utilities.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
//
// Utilities.swift
// BetterRail
//
// Created by Guy Tepper on 31/07/2021.
//

import Foundation

func formatRouteHour(_ dateString: String) -> String {

let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/yyyy HH:mm:ss"
formatter.timeZone = TimeZone(abbreviation: "UTC")
Expand All @@ -25,3 +17,24 @@ func formatRouteHour(_ dateString: String) -> String {
}
}

enum SupportedLanguages: String {
case english, hebrew, arabic
}

/// Returns the user perferred locale, lowercased.
///
/// Available options are `english`, `hebrew` and `arabic`
/// Defaults to `english`.
func getUserLocale() -> String {
let langCode = Bundle.main.preferredLocalizations[0]
let usLocale = Locale(identifier: "en-US")
var langName = "english"

if let languageName = usLocale.localizedString(forLanguageCode: langCode)?.lowercased() {
if SupportedLanguages(rawValue: languageName) != nil {
langName = languageName
}
}

return langName
}
Loading

0 comments on commit 188fa3e

Please sign in to comment.