├── .gitignore
├── .swiftpm
└── xcode
│ └── package.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── IDEWorkspaceChecks.plist
├── Example
├── .swiftlint.yml
├── Example.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── swiftpm
│ │ └── Package.resolved
└── Example
│ ├── Assets
│ ├── Assets.xcassets
│ │ ├── AccentColor.colorset
│ │ │ └── Contents.json
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ ├── Contents.json
│ │ └── logo.imageset
│ │ │ ├── Contents.json
│ │ │ └── logo.png
│ ├── ar.lproj
│ │ └── Localizable.strings
│ └── en.lproj
│ │ └── Localizable.strings
│ ├── ExampleApp.swift
│ ├── Info.plist
│ ├── Styles
│ └── AppButtonStyle.swift
│ ├── SupportFiles
│ └── Preview Content
│ │ └── Preview Assets.xcassets
│ │ └── Contents.json
│ └── Views
│ ├── AppView.swift
│ ├── LangaugeView.swift
│ ├── MainView.swift
│ └── SplashView.swift
├── Images
├── languagemanager.gif
└── logo.png
├── Package.swift
├── README.md
├── Sources
└── LanguageManagerSwiftUI
│ ├── Util
│ ├── Constants
│ │ ├── AppUserDefault.swift
│ │ └── Languages.swift
│ ├── Extensions
│ │ └── String+Helpers.swift
│ └── LanguageSettings.swift
│ └── Views
│ └── LanguageManagerView.swift
└── Tests
├── LanguageManagerSwiftUITests
├── LanguageManagerSwiftUITests.swift
└── XCTestManifests.swift
└── LinuxMain.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | /*.xcodeproj
5 | xcuserdata/
6 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example/.swiftlint.yml:
--------------------------------------------------------------------------------
1 | disabled_rules:
2 |
3 | included:
4 | - ../
5 |
6 | excluded:
7 | - Carthage
8 | - Pods
9 | - Modules
10 |
11 | identifier_name:
12 | min_length: 2
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 555C13182620AF050051C2A8 /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C13172620AF050051C2A8 /* ExampleApp.swift */; };
11 | 555C131A2620AF050051C2A8 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C13192620AF050051C2A8 /* MainView.swift */; };
12 | 555C131C2620AF080051C2A8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 555C131B2620AF080051C2A8 /* Assets.xcassets */; };
13 | 555C131F2620AF080051C2A8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 555C131E2620AF080051C2A8 /* Preview Assets.xcassets */; };
14 | 555C13292620B09C0051C2A8 /* LanguageManagerSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 555C13282620B09C0051C2A8 /* LanguageManagerSwiftUI */; };
15 | 555C132F2620B2600051C2A8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 555C13312620B2600051C2A8 /* Localizable.strings */; };
16 | 555C133A2620B4B00051C2A8 /* LangaugeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C13392620B4B00051C2A8 /* LangaugeView.swift */; };
17 | 555C13412620B8C70051C2A8 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C13402620B8C70051C2A8 /* SplashView.swift */; };
18 | 555C13442620BB2E0051C2A8 /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C13432620BB2E0051C2A8 /* AppView.swift */; };
19 | 555C134B2620F6DB0051C2A8 /* AppButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555C134A2620F6DB0051C2A8 /* AppButtonStyle.swift */; };
20 | /* End PBXBuildFile section */
21 |
22 | /* Begin PBXFileReference section */
23 | 555C13142620AF050051C2A8 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
24 | 555C13172620AF050051C2A8 /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = ""; };
25 | 555C13192620AF050051C2A8 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; };
26 | 555C131B2620AF080051C2A8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
27 | 555C131E2620AF080051C2A8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; };
28 | 555C13202620AF080051C2A8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
29 | 555C13302620B2600051C2A8 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; };
30 | 555C13332620B2630051C2A8 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = ""; };
31 | 555C13392620B4B00051C2A8 /* LangaugeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LangaugeView.swift; sourceTree = ""; };
32 | 555C13402620B8C70051C2A8 /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = ""; };
33 | 555C13432620BB2E0051C2A8 /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppView.swift; sourceTree = ""; };
34 | 555C134A2620F6DB0051C2A8 /* AppButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppButtonStyle.swift; sourceTree = ""; };
35 | /* End PBXFileReference section */
36 |
37 | /* Begin PBXFrameworksBuildPhase section */
38 | 555C13112620AF050051C2A8 /* Frameworks */ = {
39 | isa = PBXFrameworksBuildPhase;
40 | buildActionMask = 2147483647;
41 | files = (
42 | 555C13292620B09C0051C2A8 /* LanguageManagerSwiftUI in Frameworks */,
43 | );
44 | runOnlyForDeploymentPostprocessing = 0;
45 | };
46 | /* End PBXFrameworksBuildPhase section */
47 |
48 | /* Begin PBXGroup section */
49 | 555C130B2620AF050051C2A8 = {
50 | isa = PBXGroup;
51 | children = (
52 | 555C13162620AF050051C2A8 /* Example */,
53 | 555C13152620AF050051C2A8 /* Products */,
54 | );
55 | sourceTree = "";
56 | };
57 | 555C13152620AF050051C2A8 /* Products */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 555C13142620AF050051C2A8 /* Example.app */,
61 | );
62 | name = Products;
63 | sourceTree = "";
64 | };
65 | 555C13162620AF050051C2A8 /* Example */ = {
66 | isa = PBXGroup;
67 | children = (
68 | 555C13172620AF050051C2A8 /* ExampleApp.swift */,
69 | 555C133D2620B8780051C2A8 /* Views */,
70 | 555C13472620F6A00051C2A8 /* Assets */,
71 | 555C13492620F6CC0051C2A8 /* Styles */,
72 | 555C13482620F6B10051C2A8 /* SupportFiles */,
73 | 555C13202620AF080051C2A8 /* Info.plist */,
74 | );
75 | path = Example;
76 | sourceTree = "";
77 | };
78 | 555C131D2620AF080051C2A8 /* Preview Content */ = {
79 | isa = PBXGroup;
80 | children = (
81 | 555C131E2620AF080051C2A8 /* Preview Assets.xcassets */,
82 | );
83 | path = "Preview Content";
84 | sourceTree = "";
85 | };
86 | 555C133D2620B8780051C2A8 /* Views */ = {
87 | isa = PBXGroup;
88 | children = (
89 | 555C13432620BB2E0051C2A8 /* AppView.swift */,
90 | 555C13402620B8C70051C2A8 /* SplashView.swift */,
91 | 555C13192620AF050051C2A8 /* MainView.swift */,
92 | 555C13392620B4B00051C2A8 /* LangaugeView.swift */,
93 | );
94 | path = Views;
95 | sourceTree = "";
96 | };
97 | 555C13472620F6A00051C2A8 /* Assets */ = {
98 | isa = PBXGroup;
99 | children = (
100 | 555C13312620B2600051C2A8 /* Localizable.strings */,
101 | 555C131B2620AF080051C2A8 /* Assets.xcassets */,
102 | );
103 | path = Assets;
104 | sourceTree = "";
105 | };
106 | 555C13482620F6B10051C2A8 /* SupportFiles */ = {
107 | isa = PBXGroup;
108 | children = (
109 | 555C131D2620AF080051C2A8 /* Preview Content */,
110 | );
111 | path = SupportFiles;
112 | sourceTree = "";
113 | };
114 | 555C13492620F6CC0051C2A8 /* Styles */ = {
115 | isa = PBXGroup;
116 | children = (
117 | 555C134A2620F6DB0051C2A8 /* AppButtonStyle.swift */,
118 | );
119 | path = Styles;
120 | sourceTree = "";
121 | };
122 | /* End PBXGroup section */
123 |
124 | /* Begin PBXNativeTarget section */
125 | 555C13132620AF050051C2A8 /* Example */ = {
126 | isa = PBXNativeTarget;
127 | buildConfigurationList = 555C13232620AF080051C2A8 /* Build configuration list for PBXNativeTarget "Example" */;
128 | buildPhases = (
129 | C62CEEBC2966927D00369B2D /* SwiftLint */,
130 | 555C13102620AF050051C2A8 /* Sources */,
131 | 555C13112620AF050051C2A8 /* Frameworks */,
132 | 555C13122620AF050051C2A8 /* Resources */,
133 | );
134 | buildRules = (
135 | );
136 | dependencies = (
137 | );
138 | name = Example;
139 | packageProductDependencies = (
140 | 555C13282620B09C0051C2A8 /* LanguageManagerSwiftUI */,
141 | );
142 | productName = Example;
143 | productReference = 555C13142620AF050051C2A8 /* Example.app */;
144 | productType = "com.apple.product-type.application";
145 | };
146 | /* End PBXNativeTarget section */
147 |
148 | /* Begin PBXProject section */
149 | 555C130C2620AF050051C2A8 /* Project object */ = {
150 | isa = PBXProject;
151 | attributes = {
152 | LastSwiftUpdateCheck = 1240;
153 | LastUpgradeCheck = 1310;
154 | TargetAttributes = {
155 | 555C13132620AF050051C2A8 = {
156 | CreatedOnToolsVersion = 12.4;
157 | };
158 | };
159 | };
160 | buildConfigurationList = 555C130F2620AF050051C2A8 /* Build configuration list for PBXProject "Example" */;
161 | compatibilityVersion = "Xcode 9.3";
162 | developmentRegion = en;
163 | hasScannedForEncodings = 0;
164 | knownRegions = (
165 | en,
166 | Base,
167 | ar,
168 | );
169 | mainGroup = 555C130B2620AF050051C2A8;
170 | packageReferences = (
171 | 555C13272620B09C0051C2A8 /* XCRemoteSwiftPackageReference "LanguageManager-SwiftUI" */,
172 | );
173 | productRefGroup = 555C13152620AF050051C2A8 /* Products */;
174 | projectDirPath = "";
175 | projectRoot = "";
176 | targets = (
177 | 555C13132620AF050051C2A8 /* Example */,
178 | );
179 | };
180 | /* End PBXProject section */
181 |
182 | /* Begin PBXResourcesBuildPhase section */
183 | 555C13122620AF050051C2A8 /* Resources */ = {
184 | isa = PBXResourcesBuildPhase;
185 | buildActionMask = 2147483647;
186 | files = (
187 | 555C131F2620AF080051C2A8 /* Preview Assets.xcassets in Resources */,
188 | 555C132F2620B2600051C2A8 /* Localizable.strings in Resources */,
189 | 555C131C2620AF080051C2A8 /* Assets.xcassets in Resources */,
190 | );
191 | runOnlyForDeploymentPostprocessing = 0;
192 | };
193 | /* End PBXResourcesBuildPhase section */
194 |
195 | /* Begin PBXShellScriptBuildPhase section */
196 | C62CEEBC2966927D00369B2D /* SwiftLint */ = {
197 | isa = PBXShellScriptBuildPhase;
198 | alwaysOutOfDate = 1;
199 | buildActionMask = 2147483647;
200 | files = (
201 | );
202 | inputFileListPaths = (
203 | );
204 | inputPaths = (
205 | );
206 | name = SwiftLint;
207 | outputFileListPaths = (
208 | );
209 | outputPaths = (
210 | );
211 | runOnlyForDeploymentPostprocessing = 0;
212 | shellPath = /bin/sh;
213 | shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
214 | };
215 | /* End PBXShellScriptBuildPhase section */
216 |
217 | /* Begin PBXSourcesBuildPhase section */
218 | 555C13102620AF050051C2A8 /* Sources */ = {
219 | isa = PBXSourcesBuildPhase;
220 | buildActionMask = 2147483647;
221 | files = (
222 | 555C131A2620AF050051C2A8 /* MainView.swift in Sources */,
223 | 555C13412620B8C70051C2A8 /* SplashView.swift in Sources */,
224 | 555C133A2620B4B00051C2A8 /* LangaugeView.swift in Sources */,
225 | 555C134B2620F6DB0051C2A8 /* AppButtonStyle.swift in Sources */,
226 | 555C13442620BB2E0051C2A8 /* AppView.swift in Sources */,
227 | 555C13182620AF050051C2A8 /* ExampleApp.swift in Sources */,
228 | );
229 | runOnlyForDeploymentPostprocessing = 0;
230 | };
231 | /* End PBXSourcesBuildPhase section */
232 |
233 | /* Begin PBXVariantGroup section */
234 | 555C13312620B2600051C2A8 /* Localizable.strings */ = {
235 | isa = PBXVariantGroup;
236 | children = (
237 | 555C13302620B2600051C2A8 /* en */,
238 | 555C13332620B2630051C2A8 /* ar */,
239 | );
240 | name = Localizable.strings;
241 | sourceTree = "";
242 | };
243 | /* End PBXVariantGroup section */
244 |
245 | /* Begin XCBuildConfiguration section */
246 | 555C13212620AF080051C2A8 /* Debug */ = {
247 | isa = XCBuildConfiguration;
248 | buildSettings = {
249 | ALWAYS_SEARCH_USER_PATHS = NO;
250 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
251 | CLANG_ANALYZER_NONNULL = YES;
252 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
253 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
254 | CLANG_CXX_LIBRARY = "libc++";
255 | CLANG_ENABLE_MODULES = YES;
256 | CLANG_ENABLE_OBJC_ARC = YES;
257 | CLANG_ENABLE_OBJC_WEAK = YES;
258 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
259 | CLANG_WARN_BOOL_CONVERSION = YES;
260 | CLANG_WARN_COMMA = YES;
261 | CLANG_WARN_CONSTANT_CONVERSION = YES;
262 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
263 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
264 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
265 | CLANG_WARN_EMPTY_BODY = YES;
266 | CLANG_WARN_ENUM_CONVERSION = YES;
267 | CLANG_WARN_INFINITE_RECURSION = YES;
268 | CLANG_WARN_INT_CONVERSION = YES;
269 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
270 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
271 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
272 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
273 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
274 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
275 | CLANG_WARN_STRICT_PROTOTYPES = YES;
276 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
277 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
278 | CLANG_WARN_UNREACHABLE_CODE = YES;
279 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
280 | COPY_PHASE_STRIP = NO;
281 | DEBUG_INFORMATION_FORMAT = dwarf;
282 | ENABLE_STRICT_OBJC_MSGSEND = YES;
283 | ENABLE_TESTABILITY = YES;
284 | GCC_C_LANGUAGE_STANDARD = gnu11;
285 | GCC_DYNAMIC_NO_PIC = NO;
286 | GCC_NO_COMMON_BLOCKS = YES;
287 | GCC_OPTIMIZATION_LEVEL = 0;
288 | GCC_PREPROCESSOR_DEFINITIONS = (
289 | "DEBUG=1",
290 | "$(inherited)",
291 | );
292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
294 | GCC_WARN_UNDECLARED_SELECTOR = YES;
295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
296 | GCC_WARN_UNUSED_FUNCTION = YES;
297 | GCC_WARN_UNUSED_VARIABLE = YES;
298 | IPHONEOS_DEPLOYMENT_TARGET = 14.4;
299 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
300 | MTL_FAST_MATH = YES;
301 | ONLY_ACTIVE_ARCH = YES;
302 | SDKROOT = iphoneos;
303 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
304 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
305 | };
306 | name = Debug;
307 | };
308 | 555C13222620AF080051C2A8 /* Release */ = {
309 | isa = XCBuildConfiguration;
310 | buildSettings = {
311 | ALWAYS_SEARCH_USER_PATHS = NO;
312 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
313 | CLANG_ANALYZER_NONNULL = YES;
314 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
316 | CLANG_CXX_LIBRARY = "libc++";
317 | CLANG_ENABLE_MODULES = YES;
318 | CLANG_ENABLE_OBJC_ARC = YES;
319 | CLANG_ENABLE_OBJC_WEAK = YES;
320 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
321 | CLANG_WARN_BOOL_CONVERSION = YES;
322 | CLANG_WARN_COMMA = YES;
323 | CLANG_WARN_CONSTANT_CONVERSION = YES;
324 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
326 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
327 | CLANG_WARN_EMPTY_BODY = YES;
328 | CLANG_WARN_ENUM_CONVERSION = YES;
329 | CLANG_WARN_INFINITE_RECURSION = YES;
330 | CLANG_WARN_INT_CONVERSION = YES;
331 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
332 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
333 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
334 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
335 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
336 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
337 | CLANG_WARN_STRICT_PROTOTYPES = YES;
338 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
339 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
340 | CLANG_WARN_UNREACHABLE_CODE = YES;
341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
342 | COPY_PHASE_STRIP = NO;
343 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
344 | ENABLE_NS_ASSERTIONS = NO;
345 | ENABLE_STRICT_OBJC_MSGSEND = YES;
346 | GCC_C_LANGUAGE_STANDARD = gnu11;
347 | GCC_NO_COMMON_BLOCKS = YES;
348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
350 | GCC_WARN_UNDECLARED_SELECTOR = YES;
351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
352 | GCC_WARN_UNUSED_FUNCTION = YES;
353 | GCC_WARN_UNUSED_VARIABLE = YES;
354 | IPHONEOS_DEPLOYMENT_TARGET = 14.4;
355 | MTL_ENABLE_DEBUG_INFO = NO;
356 | MTL_FAST_MATH = YES;
357 | SDKROOT = iphoneos;
358 | SWIFT_COMPILATION_MODE = wholemodule;
359 | SWIFT_OPTIMIZATION_LEVEL = "-O";
360 | VALIDATE_PRODUCT = YES;
361 | };
362 | name = Release;
363 | };
364 | 555C13242620AF080051C2A8 /* Debug */ = {
365 | isa = XCBuildConfiguration;
366 | buildSettings = {
367 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
368 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
369 | CODE_SIGN_STYLE = Automatic;
370 | DEVELOPMENT_ASSET_PATHS = "\"Example/SupportFiles/Preview Content\"";
371 | ENABLE_PREVIEWS = YES;
372 | INFOPLIST_FILE = Example/Info.plist;
373 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
374 | LD_RUNPATH_SEARCH_PATHS = (
375 | "$(inherited)",
376 | "@executable_path/Frameworks",
377 | );
378 | PRODUCT_BUNDLE_IDENTIFIER = com.abedalkareem.Example;
379 | PRODUCT_NAME = "$(TARGET_NAME)";
380 | SWIFT_VERSION = 5.0;
381 | TARGETED_DEVICE_FAMILY = "1,2";
382 | };
383 | name = Debug;
384 | };
385 | 555C13252620AF080051C2A8 /* Release */ = {
386 | isa = XCBuildConfiguration;
387 | buildSettings = {
388 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
389 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
390 | CODE_SIGN_STYLE = Automatic;
391 | DEVELOPMENT_ASSET_PATHS = "\"Example/SupportFiles/Preview Content\"";
392 | ENABLE_PREVIEWS = YES;
393 | INFOPLIST_FILE = Example/Info.plist;
394 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
395 | LD_RUNPATH_SEARCH_PATHS = (
396 | "$(inherited)",
397 | "@executable_path/Frameworks",
398 | );
399 | PRODUCT_BUNDLE_IDENTIFIER = com.abedalkareem.Example;
400 | PRODUCT_NAME = "$(TARGET_NAME)";
401 | SWIFT_VERSION = 5.0;
402 | TARGETED_DEVICE_FAMILY = "1,2";
403 | };
404 | name = Release;
405 | };
406 | /* End XCBuildConfiguration section */
407 |
408 | /* Begin XCConfigurationList section */
409 | 555C130F2620AF050051C2A8 /* Build configuration list for PBXProject "Example" */ = {
410 | isa = XCConfigurationList;
411 | buildConfigurations = (
412 | 555C13212620AF080051C2A8 /* Debug */,
413 | 555C13222620AF080051C2A8 /* Release */,
414 | );
415 | defaultConfigurationIsVisible = 0;
416 | defaultConfigurationName = Release;
417 | };
418 | 555C13232620AF080051C2A8 /* Build configuration list for PBXNativeTarget "Example" */ = {
419 | isa = XCConfigurationList;
420 | buildConfigurations = (
421 | 555C13242620AF080051C2A8 /* Debug */,
422 | 555C13252620AF080051C2A8 /* Release */,
423 | );
424 | defaultConfigurationIsVisible = 0;
425 | defaultConfigurationName = Release;
426 | };
427 | /* End XCConfigurationList section */
428 |
429 | /* Begin XCRemoteSwiftPackageReference section */
430 | 555C13272620B09C0051C2A8 /* XCRemoteSwiftPackageReference "LanguageManager-SwiftUI" */ = {
431 | isa = XCRemoteSwiftPackageReference;
432 | repositoryURL = "https://github.com/Abedalkareem/LanguageManager-SwiftUI";
433 | requirement = {
434 | kind = upToNextMajorVersion;
435 | minimumVersion = 0.0.1;
436 | };
437 | };
438 | /* End XCRemoteSwiftPackageReference section */
439 |
440 | /* Begin XCSwiftPackageProductDependency section */
441 | 555C13282620B09C0051C2A8 /* LanguageManagerSwiftUI */ = {
442 | isa = XCSwiftPackageProductDependency;
443 | package = 555C13272620B09C0051C2A8 /* XCRemoteSwiftPackageReference "LanguageManager-SwiftUI" */;
444 | productName = LanguageManagerSwiftUI;
445 | };
446 | /* End XCSwiftPackageProductDependency section */
447 | };
448 | rootObject = 555C130C2620AF050051C2A8 /* Project object */;
449 | }
450 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved:
--------------------------------------------------------------------------------
1 | {
2 | "object": {
3 | "pins": [
4 | {
5 | "package": "LanguageManagerSwiftUI",
6 | "repositoryURL": "https://github.com/Abedalkareem/LanguageManager-SwiftUI",
7 | "state": {
8 | "branch": null,
9 | "revision": "309ae4ad2fd89902bf560e34dcbee10f2986abda",
10 | "version": "0.0.4"
11 | }
12 | }
13 | ]
14 | },
15 | "version": 1
16 | }
17 |
--------------------------------------------------------------------------------
/Example/Example/Assets/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Example/Example/Assets/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "scale" : "1x",
46 | "size" : "20x20"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "scale" : "2x",
51 | "size" : "20x20"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "scale" : "1x",
56 | "size" : "29x29"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "scale" : "2x",
61 | "size" : "29x29"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "scale" : "1x",
66 | "size" : "40x40"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "scale" : "2x",
71 | "size" : "40x40"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "scale" : "1x",
76 | "size" : "76x76"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "scale" : "2x",
81 | "size" : "76x76"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "scale" : "2x",
86 | "size" : "83.5x83.5"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "scale" : "1x",
91 | "size" : "1024x1024"
92 | }
93 | ],
94 | "info" : {
95 | "author" : "xcode",
96 | "version" : 1
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Example/Example/Assets/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Example/Example/Assets/Assets.xcassets/logo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "filename" : "logo.png",
5 | "idiom" : "universal",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "author" : "xcode",
19 | "version" : 1
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Example/Example/Assets/Assets.xcassets/logo.imageset/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Abedalkareem/LanguageManager-SwiftUI/c849b0329eba3e9514d3a230a216f6040e20e6c5/Example/Example/Assets/Assets.xcassets/logo.imageset/logo.png
--------------------------------------------------------------------------------
/Example/Example/Assets/ar.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | /*
2 | Localizable.strings
3 | Example
4 |
5 | Created by abedalkareem omreyh on 09/04/2021.
6 |
7 | */
8 |
9 | "Hello" = "مرحبا!";
10 | "About" = "كان لوريم إيبسوم ولايزال المعيار للنص الشكلي منذ القرن الخامس عشر عندما قامت مطبعة مجهولة برص مجموعة من الأحرف بشكل عشوائي أخذتها من نص، لتكوّن كتيّب بمثابة دليل أو مرجع شكلي لهذه الأحرف.";
11 | "Change the language" = "غير اللغة";
12 | "Arabic" = "عربي";
13 | "English" = "English";
14 | "Welcome!" = "اهلا وسهلا!";
15 | "Select a language" = "اختر لغة";
16 |
--------------------------------------------------------------------------------
/Example/Example/Assets/en.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | /*
2 | Localizable.strings
3 | Example
4 |
5 | Created by abedalkareem omreyh on 09/04/2021.
6 |
7 | */
8 |
9 | "Hello" = "Hello!";
10 | "About" = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.";
11 | "Change the language" = "Change the language";
12 | "Arabic" = "Arabic";
13 | "English" = "English";
14 | "Welcome!" = "Welcome!";
15 | "Select a language" = "Select a language";
16 |
--------------------------------------------------------------------------------
/Example/Example/ExampleApp.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ExampleApp.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 | import LanguageManagerSwiftUI
10 |
11 | @main
12 | struct ExampleApp: App {
13 | var body: some Scene {
14 | WindowGroup {
15 | // The default language when the app starts for the first time.
16 | // it can be the `deviceLanguage`, `ar`, `en`, or any language.
17 | LanguageManagerView(.deviceLanguage) {
18 | AppView()
19 | .transition(.slide) // The animation that will be happening when the language change.
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Example/Example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UIApplicationSceneManifest
24 |
25 | UIApplicationSupportsMultipleScenes
26 |
27 |
28 | UIApplicationSupportsIndirectInputEvents
29 |
30 | UILaunchScreen
31 |
32 | UIRequiredDeviceCapabilities
33 |
34 | armv7
35 |
36 | UISupportedInterfaceOrientations
37 |
38 | UIInterfaceOrientationPortrait
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UISupportedInterfaceOrientations~ipad
43 |
44 | UIInterfaceOrientationPortrait
45 | UIInterfaceOrientationPortraitUpsideDown
46 | UIInterfaceOrientationLandscapeLeft
47 | UIInterfaceOrientationLandscapeRight
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/Example/Example/Styles/AppButtonStyle.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppButtonStyle.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 10/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | struct AppButtonStyle: PrimitiveButtonStyle {
11 |
12 | func makeBody(configuration: PrimitiveButtonStyleConfiguration) -> some View {
13 | AppButton(configuration: configuration)
14 | }
15 |
16 | struct AppButton: View {
17 |
18 | // MARK: State properties
19 |
20 | @State var focused: Bool = false
21 |
22 | // MARK: - Properties
23 |
24 | let configuration: PrimitiveButtonStyle.Configuration
25 |
26 | // MARK: - Body
27 |
28 | var body: some View {
29 | return GeometryReader { geometry in
30 | Rectangle()
31 | .fill(Color.black)
32 | .overlay(
33 | configuration.label
34 | .foregroundColor(.white)
35 | )
36 | .cornerRadius(geometry.size.height / 2)
37 | }
38 | .scaleEffect(focused ? 1.1 : 1.0)
39 | .frame(maxWidth: .infinity, minHeight: 50, maxHeight: 50)
40 | .padding()
41 | .gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
42 | .onChanged { _ in
43 | withAnimation {
44 | self.focused = true
45 | }
46 | }
47 | .onEnded { _ in
48 | withAnimation {
49 | self.focused = false
50 | configuration.trigger()
51 | }
52 | })
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Example/Example/SupportFiles/Preview Content/Preview Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Example/Example/Views/AppView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppView.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | struct AppView: View {
11 |
12 | // MARK: - State properties
13 |
14 | @State var showMainScreen = false
15 |
16 | // MARK: - body
17 |
18 | var body: some View {
19 | Group {
20 | if showMainScreen {
21 | MainView()
22 | } else {
23 | SplashView()
24 | }
25 | }
26 | .onAppear(perform: onAppear)
27 | }
28 |
29 | // MARK: -
30 |
31 | private func onAppear() {
32 | DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
33 | showMainScreen = true
34 | }
35 | }
36 | }
37 |
38 | // MARK: - Previews
39 |
40 | struct AppView_Previews: PreviewProvider {
41 | static var previews: some View {
42 | AppView()
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Example/Example/Views/LangaugeView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LangaugeView.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 | import LanguageManagerSwiftUI
10 |
11 | struct LangaugeView: View {
12 |
13 | // MARK: - Properties
14 |
15 | @EnvironmentObject var languageSettings: LanguageSettings
16 |
17 | // MARK: - body
18 |
19 | var body: some View {
20 | VStack {
21 | Text("Select a language")
22 | .fontWeight(.bold)
23 | .padding()
24 | Button("Arabic") {
25 | withAnimation {
26 | languageSettings.selectedLanguage = .ar
27 | }
28 | }
29 | Button("English") {
30 | withAnimation {
31 | languageSettings.selectedLanguage = .en
32 | }
33 | }
34 | }
35 | .buttonStyle(AppButtonStyle())
36 | }
37 | }
38 |
39 | // MARK: - Previews
40 |
41 | struct LangaugeView_Previews: PreviewProvider {
42 | static var previews: some View {
43 | LangaugeView()
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Example/Example/Views/MainView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MainView.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | struct MainView: View {
11 |
12 | // MARK: - State properties
13 |
14 | @State private var isPresented = false
15 |
16 | // MARK: - body
17 |
18 | var body: some View {
19 | VStack {
20 | Image("logo")
21 | .resizable()
22 | .aspectRatio(contentMode: .fit)
23 | .frame(width: 240, height: 100)
24 | Text("Hello")
25 | .fontWeight(.bold)
26 | .padding()
27 | Text("About")
28 | .padding()
29 | Button("Change the language") {
30 | isPresented = true
31 | }
32 | }
33 | .buttonStyle(AppButtonStyle())
34 | .fullScreenCover(isPresented: $isPresented) {
35 | LangaugeView()
36 | }
37 | }
38 | }
39 |
40 | // MARK: - Previews
41 |
42 | struct MainView_Previews: PreviewProvider {
43 | static var previews: some View {
44 | MainView()
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Example/Example/Views/SplashView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SplashView.swift
3 | // Example
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | struct SplashView: View {
11 |
12 | // MARK: - body
13 |
14 | var body: some View {
15 | VStack {
16 | Spacer()
17 | Image("logo")
18 | .resizable()
19 | .aspectRatio(contentMode: .fit)
20 | .frame(width: 240, height: 100)
21 | Spacer()
22 | Text("Welcome!")
23 | .fontWeight(.bold)
24 | Spacer()
25 | }
26 | }
27 | }
28 |
29 | // MARK: - Previews
30 |
31 | struct SplashView_Previews: PreviewProvider {
32 | static var previews: some View {
33 | SplashView()
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Images/languagemanager.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Abedalkareem/LanguageManager-SwiftUI/c849b0329eba3e9514d3a230a216f6040e20e6c5/Images/languagemanager.gif
--------------------------------------------------------------------------------
/Images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Abedalkareem/LanguageManager-SwiftUI/c849b0329eba3e9514d3a230a216f6040e20e6c5/Images/logo.png
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.3
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | import PackageDescription
5 |
6 | let package = Package(
7 | name: "LanguageManagerSwiftUI",
8 | platforms: [.iOS(.v13), .macOS(.v10_15)],
9 | products: [
10 | // Products define the executables and libraries a package produces, and make them visible to other packages.
11 | .library(
12 | name: "LanguageManagerSwiftUI",
13 | targets: ["LanguageManagerSwiftUI"])
14 | ],
15 | dependencies: [
16 | // Dependencies declare other packages that this package depends on.
17 | // .package(url: /* package url */, from: "1.0.0"),
18 | ],
19 | targets: [
20 | // Targets are the basic building blocks of a package. A target can define a module or a test suite.
21 | // Targets can depend on other targets in this package, and on products in packages this package depends on.
22 | .target(
23 | name: "LanguageManagerSwiftUI",
24 | dependencies: []),
25 | .testTarget(
26 | name: "LanguageManagerSwiftUITests",
27 | dependencies: ["LanguageManagerSwiftUI"])
28 | ]
29 | )
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [](https://t.me/+NvUXzshmIg44N2M0)
3 | [](https://www.youtube.com/c/Omreyh)
4 | [](https://twitter.com/abedalkareemomr)
5 |
6 |
7 |
8 |
9 |
10 |
11 | A Language manager to handle changing app language without restarting the app.
12 |
13 |
14 |
15 |
16 | ## ScreenShots
17 |
18 |
19 |
20 | ## Usage
21 |
22 | First of all, remember to add the ```Localizable.strings``` to your project, after adding the ```Localizable.strings``` file, select it then go to file inspector and below localization press localize, after that go to ```PROJECT > Localisation``` then add the languages you want to support (Arabic for example), dialog will appear to ask you which resource file you want to localize, select just the ```Localizable.strings``` file.
23 | Now, add a ```Text``` view and then add a text to it, for example ```"Hello !"```, then go to your ```Localizable.strings``` file expand it, you will find Localizable strings file for English and Arabic, for English enter this line with the string you used in the ```Text``` view that we just mentioned before
24 | ```"Hello !" = "Hello !";```
25 | and for Arabic file :
26 | ```"Hello !" = "مرحبا !";```
27 |
28 |
29 |
30 |
31 | After that in you need to wrap your main view with ```LanguageManagerView``` and pass the default language that your app will run first time
32 |
33 | ```swift
34 | @main
35 | struct ExampleApp: App {
36 | var body: some Scene {
37 | WindowGroup {
38 | // The default language when the app starts for the first time.
39 | // it can be the `deviceLanguage`, `ar`, `en`, or any language.
40 | LanguageManagerView(.deviceLanguage) {
41 | AppView()
42 | .transition(.slide) // The animation that will be happening when the language change.
43 | }
44 | }
45 | }
46 | }
47 | ```
48 |
49 | If you want to change the language you should change the ```selectedLanguage``` as below
50 |
51 | ```swift
52 | struct LangaugeView: View {
53 |
54 | // MARK: - Properties
55 |
56 | @EnvironmentObject var languageSettings: LanguageSettings
57 |
58 | // MARK: - body
59 |
60 | var body: some View {
61 | VStack {
62 | Text("Select a language")
63 | .padding()
64 | Button("Arabic") {
65 | withAnimation {
66 | languageSettings.selectedLanguage = .ar
67 | }
68 | }
69 | .padding()
70 | Button("English") {
71 | withAnimation {
72 | languageSettings.selectedLanguage = .en
73 | }
74 | }
75 | }
76 | }
77 | }
78 | ```
79 |
80 | ## Installation
81 |
82 | LanguageManager-iOS is available through [Swift Package Manager](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).
83 |
84 | ## Support me 🚀
85 |
86 | You can support this project by:
87 |
88 | 1- Checking my [apps](https://apps.apple.com/us/developer/id928910207).
89 | 2- Star the repo.
90 | 3- Share the repo with your friends.
91 |
92 | ## Follow me ❤️
93 |
94 | [Facebook](https://www.facebook.com/Abedalkareem.Omreyh/) | [Twitter](http://twitter.com/abedalkareemomr) | [Instagram](http://instagram.com/abedalkareemomreyh/) | [Youtube](https://www.youtube.com/user/AbedalkareemOmreyh)
95 |
96 | ## License
97 |
98 | ```
99 | The MIT License (MIT)
100 |
101 | Copyright (c) 2021 Abedalkareem
102 |
103 | Permission is hereby granted, free of charge, to any person obtaining a copy
104 | of this software and associated documentation files (the "Software"), to deal
105 | in the Software without restriction, including without limitation the rights
106 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107 | copies of the Software, and to permit persons to whom the Software is
108 | furnished to do so, subject to the following conditions:
109 |
110 | The above copyright notice and this permission notice shall be included in all
111 | copies or substantial portions of the Software.
112 |
113 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
115 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
116 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
117 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
118 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
119 | SOFTWARE.
120 | ```
121 |
--------------------------------------------------------------------------------
/Sources/LanguageManagerSwiftUI/Util/Constants/AppUserDefault.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppUserDefault.swift
3 | // LanguageManagerSwiftUI
4 | //
5 | // Created by abedalkareem omreyh on 06/04/2021.
6 | //
7 |
8 | import Foundation
9 |
10 | @propertyWrapper
11 | struct AppUserDefault {
12 | let key: String
13 | let defaultValue: T
14 |
15 | init(_ key: DefaultsKeys, defaultValue: T) {
16 | self.key = key.rawValue
17 | self.defaultValue = defaultValue
18 | }
19 |
20 | var wrappedValue: T {
21 | get {
22 | return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
23 | }
24 | set {
25 | UserDefaults.standard.set(newValue, forKey: key)
26 | }
27 | }
28 | }
29 |
30 | enum DefaultsKeys: String {
31 | case selectedLanguage = "LanguageManagerSelectedLanguage"
32 | }
33 |
--------------------------------------------------------------------------------
/Sources/LanguageManagerSwiftUI/Util/Constants/Languages.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Languages.swift
3 | // LanguageManagerSwiftUI
4 | //
5 | // Created by abedalkareem omreyh on 06/04/2021.
6 | //
7 |
8 | import Foundation
9 |
10 | public enum Languages: String {
11 | case ar,ps, en, nl, ja, ko, vi, ru, sv, fr, es, pt, it, de, da, fi, nb, tr, el, id,
12 | ms, th, hi, hu, pl, cs, sk, uk, hr, ca, ro, he, ur, fa, ku, arc, sl, ml, am
13 | case enGB = "en-GB"
14 | case enAU = "en-AU"
15 | case enCA = "en-CA"
16 | case enIN = "en-IN"
17 | case frCA = "fr-CA"
18 | case esMX = "es-MX"
19 | case ptBR = "pt-BR"
20 | case zhHans = "zh-Hans"
21 | case zhHant = "zh-Hant"
22 | case zhHK = "zh-HK"
23 | case es419 = "es-419"
24 | case ptPT = "pt-PT"
25 | case deviceLanguage
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/LanguageManagerSwiftUI/Util/Extensions/String+Helpers.swift:
--------------------------------------------------------------------------------
1 | //
2 | // File.swift
3 | //
4 | //
5 | // Created by abedalkareem omreyh on 09/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | public extension String {
11 | ///
12 | /// Returns localized key for the string.
13 | ///
14 | var localizedKey: LocalizedStringKey {
15 | return LocalizedStringKey(self)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Sources/LanguageManagerSwiftUI/Util/LanguageSettings.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LanguageSettings.swift
3 | // LanguageManagerSwiftUI
4 | //
5 | // Created by abedalkareem omreyh on 06/04/2021.
6 | //
7 |
8 | import Combine
9 | import SwiftUI
10 |
11 | public class LanguageSettings: ObservableObject {
12 |
13 | // MARK: - Properties
14 |
15 | ///
16 | /// Current app local. It's passed to the views as `environment` so they can use it to localise strings.
17 | /// Also, you can use it to localise the currency or to use it with a `NSDateFormatter`.
18 | ///
19 | public var local: Locale {
20 | Locale(identifier: selectedLanguage.rawValue)
21 | }
22 |
23 | ///
24 | /// The device preferred language.
25 | /// The device language is deffrent than the app language, it's the language the user is using for his device.
26 | /// To get the app language use `selectedLanguage`.
27 | ///
28 | public var deviceLanguage: Languages? {
29 | guard let deviceLanguage = Bundle.main.preferredLocalizations.first else {
30 | return nil
31 | }
32 | return Languages(rawValue: deviceLanguage)
33 | }
34 |
35 | ///
36 | /// The direction of the language. You can expect one of these values, `rightToLeft` or `leftToRight`.
37 | ///
38 | public var layout: LayoutDirection {
39 | isRightToLeft ? .rightToLeft : .leftToRight
40 | }
41 |
42 | ///
43 | /// The diriction of the language as boolean.
44 | ///
45 | public var isRightToLeft: Bool {
46 | isLanguageRightToLeft(language: selectedLanguage)
47 | }
48 |
49 | ///
50 | /// A unique id used to refresh the view.
51 | ///
52 | var uuid: String {
53 | UUID().uuidString
54 | }
55 |
56 | // MARK: - State properties
57 |
58 | ///
59 | /// The current app selected language.
60 | /// Changing this value will refresh your views with the new selected language.
61 | /// The default language is the device language, so if the user device language is arabic,
62 | /// the app language will be arabic.
63 | ///
64 | @Published public var selectedLanguage: Languages = .deviceLanguage
65 |
66 | // MARK: - Private properties
67 |
68 | private var bag = Set()
69 |
70 | @AppUserDefault(.selectedLanguage, defaultValue: nil)
71 | private var _language: String?
72 |
73 | // MARK: - init
74 |
75 | public init(defaultLanguage: Languages) {
76 | if _language == nil {
77 | _language = (defaultLanguage == .deviceLanguage ? deviceLanguage : defaultLanguage).map { $0.rawValue }
78 | }
79 |
80 | selectedLanguage = Languages(rawValue: _language!)!
81 |
82 | observeForSelectedLanguage()
83 | }
84 |
85 | // MARK: - Methods
86 |
87 | private func observeForSelectedLanguage() {
88 | $selectedLanguage
89 | .map({ $0.rawValue })
90 | .sink { [weak self] value in
91 | self?._language = value
92 | }
93 | .store(in: &bag)
94 | }
95 |
96 | private func isLanguageRightToLeft(language: Languages) -> Bool {
97 | return Locale.characterDirection(forLanguage: language.rawValue) == .rightToLeft
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Sources/LanguageManagerSwiftUI/Views/LanguageManagerView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LanguageManagerView.swift
3 | // LanguageManagerSwiftUI
4 | //
5 | // Created by abedalkareem omreyh on 06/04/2021.
6 | //
7 |
8 | import SwiftUI
9 |
10 | public struct LanguageManagerView: View {
11 |
12 | // MARK: - Private properties
13 |
14 | private let content: Content
15 | @ObservedObject private var settings: LanguageSettings
16 |
17 | // MARK: init
18 |
19 | ///
20 | /// - Parameters:
21 | /// - defaultLanguage: The default language when the app starts for the first time.
22 | ///
23 | public init(_ defaultLanguage: Languages, content: () -> Content) {
24 | self.content = content()
25 | self.settings = LanguageSettings(defaultLanguage: defaultLanguage)
26 | }
27 |
28 | // MARK: - body
29 |
30 | public var body: some View {
31 | content
32 | .environment(\.locale, settings.local)
33 | .environment(\.layoutDirection, settings.layout)
34 | .id(settings.uuid)
35 | .environmentObject(settings)
36 | }
37 | }
38 |
39 | // MARK: - Previews
40 |
41 | struct LanguageManagerView_Previews: PreviewProvider {
42 | static var previews: some View {
43 | LanguageManagerView(.deviceLanguage) {
44 | Text("Hi")
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Tests/LanguageManagerSwiftUITests/LanguageManagerSwiftUITests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 | @testable import LanguageManagerSwiftUI
3 |
4 | final class LanguageManagerSwiftUITests: XCTestCase {
5 | func testExample() {
6 |
7 | }
8 |
9 | static var allTests = [
10 | ("testExample", testExample)
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/LanguageManagerSwiftUITests/XCTestManifests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 |
3 | #if !canImport(ObjectiveC)
4 | public func allTests() -> [XCTestCaseEntry] {
5 | return [
6 | testCase(LanguageManagerSwiftUITests.allTests)
7 | ]
8 | }
9 | #endif
10 |
--------------------------------------------------------------------------------
/Tests/LinuxMain.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 |
3 | import LanguageManagerSwiftUITests
4 |
5 | var tests = [XCTestCaseEntry]()
6 | tests += LanguageManagerSwiftUITests.allTests()
7 | XCTMain(tests)
8 |
--------------------------------------------------------------------------------