diff --git a/Example/LocalizeExample/LocalizeExample.xcodeproj/project.pbxproj b/Example/LocalizeExample/LocalizeExample.xcodeproj/project.pbxproj index 63a4d0a..8b1e474 100644 --- a/Example/LocalizeExample/LocalizeExample.xcodeproj/project.pbxproj +++ b/Example/LocalizeExample/LocalizeExample.xcodeproj/project.pbxproj @@ -7,11 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + 2768922E25915C5600F439FA /* Localizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2768922D25915C5600F439FA /* Localizable.swift */; }; 994630691FAC68410004A9A2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 994630681FAC68410004A9A2 /* AppDelegate.swift */; }; 9946306B1FAC68410004A9A2 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9946306A1FAC68410004A9A2 /* ViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 2768922D25915C5600F439FA /* Localizable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Localizable.swift; sourceTree = ""; }; 994630651FAC68410004A9A2 /* LocalizeExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LocalizeExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 994630681FAC68410004A9A2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 9946306A1FAC68410004A9A2 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -83,6 +85,7 @@ isa = PBXGroup; children = ( 99EB549A1FAC6D3300AD728C /* Localizable.strings */, + 2768922D25915C5600F439FA /* Localizable.swift */, ); path = Languages; sourceTree = ""; @@ -115,7 +118,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = freshos; TargetAttributes = { 994630641FAC68410004A9A2 = { @@ -178,6 +181,7 @@ buildActionMask = 2147483647; files = ( 9946306B1FAC68410004A9A2 /* ViewController.swift in Sources */, + 2768922E25915C5600F439FA /* Localizable.swift in Sources */, 994630691FAC68410004A9A2 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -213,6 +217,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -220,8 +225,10 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -247,7 +254,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -271,6 +278,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -278,8 +286,10 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -299,7 +309,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Example/LocalizeExample/LocalizeExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/LocalizeExample/LocalizeExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/LocalizeExample/LocalizeExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/LocalizeExample/Resources/Languages/Localizable.swift b/Example/LocalizeExample/Resources/Languages/Localizable.swift new file mode 100644 index 0000000..e7746ba --- /dev/null +++ b/Example/LocalizeExample/Resources/Languages/Localizable.swift @@ -0,0 +1,24 @@ +// +// Localizable.swift +// LocalizeExample +// +// Created by Kaiser Abliz on 12/21/20. +// Copyright © 2020 freshos. All rights reserved. +// + +import Foundation + +enum Localizable: String { + + case title_test + + var localized: String { + return self.rawValue.localized + } +} + +extension String { + var localized: String { + return NSLocalizedString(self, comment: "") + } +} diff --git a/Example/LocalizeExample/Resources/Languages/en.lproj/Localizable.strings b/Example/LocalizeExample/Resources/Languages/en.lproj/Localizable.strings index 243ee66..8f82b2e 100644 --- a/Example/LocalizeExample/Resources/Languages/en.lproj/Localizable.strings +++ b/Example/LocalizeExample/Resources/Languages/en.lproj/Localizable.strings @@ -4,3 +4,4 @@ "UntranslatedKey" = "Hey I'm always in english so you need to translate me!"; "DuplicatedKey" = "Hey, I'm here more than once!"; "DuplicatedKey" = "Hey, I'm here more than once!"; +"title_test" = "title_test en"; diff --git a/Example/LocalizeExample/Resources/Languages/es.lproj/Localizable.strings b/Example/LocalizeExample/Resources/Languages/es.lproj/Localizable.strings index 9cae10b..b774a6d 100644 --- a/Example/LocalizeExample/Resources/Languages/es.lproj/Localizable.strings +++ b/Example/LocalizeExample/Resources/Languages/es.lproj/Localizable.strings @@ -3,3 +3,4 @@ "UntranslatedKey" = "Hey I'm always in english so you need to translate me!"; "DuplicatedKey" = "Hey, I'm more than once in the master translations!"; "RedundantKey" = "Hi, I'm a redundant key only appearing in Spanish"; +"title_test" = "title_test sp"; diff --git a/Example/LocalizeExample/Resources/Languages/fr.lproj/Localizable.strings b/Example/LocalizeExample/Resources/Languages/fr.lproj/Localizable.strings index de33d5f..169cd6b 100644 --- a/Example/LocalizeExample/Resources/Languages/fr.lproj/Localizable.strings +++ b/Example/LocalizeExample/Resources/Languages/fr.lproj/Localizable.strings @@ -3,3 +3,4 @@ "NeverUsedKey" = "Bonjour I'm never used so you can just get rid of me!"; "DuplicatedKey" = "Hey, I'm more than once in the master translations!"; "UntranslatedKey" = "Hey I'm always in english so you need to translate me!"; +"title_test" = "title_test fr"; diff --git a/Example/LocalizeExample/Sources/ViewController.swift b/Example/LocalizeExample/Sources/ViewController.swift index 3d1ccc8..2f9f062 100644 --- a/Example/LocalizeExample/Sources/ViewController.swift +++ b/Example/LocalizeExample/Sources/ViewController.swift @@ -18,5 +18,6 @@ final class ViewController: UIViewController { _ = NSLocalizedString("MissingKey", comment: "") _ = NSLocalizedString("DuplicatedKey", comment: "") _ = NSLocalizedString("MissingKeyFromMain", comment: "This key is not present in master translation file") + _ = Localizable.title_test.localized } } diff --git a/Localize.swift b/Localize.swift index 625caf1..5e6f078 100755 --- a/Localize.swift +++ b/Localize.swift @@ -34,7 +34,8 @@ let patterns = [ "Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)", // Laurine Calls "L10n.tr\\(key: \"(\\w+)\"", // SwiftGen generation "ypLocalized\\(\"(.*)\"\\)", - "\"(.*)\".localized" // "key".localized pattern + "\"(.*)\".localized", // "key".localized pattern + "Localizable\\.((?:[a-z]*[A-z]*)*)\\.localized" ] /* @@ -139,15 +140,17 @@ struct LocalizationFiles { let lines = string.components(separatedBy: .newlines) keyValue = [:] - let pattern = "\"(.*)\" = \"(.+)\";" + let pattern = "\"(.*)\"=\"(.+)\";" let regex = try? NSRegularExpression(pattern: pattern, options: []) var ignoredTranslation: [String] = [] for (lineNumber, line) in lines.enumerated() { + //white Space Trimmed Line + let line = line.replacingOccurrences(of: " ", with: "") let range = NSRange(location: 0, length: (line as NSString).length) // Ignored pattern - let ignoredPattern = "\"(.*)\" = \"(.+)\"; *\\/\\/ *ignore-same-translation-warning" + let ignoredPattern = "\"(.*)\"=\"(.+)\"; *\\/\\/ *ignore-same-translation-warning" let ignoredRegex = try? NSRegularExpression(pattern: ignoredPattern, options: []) if let ignoredMatch = ignoredRegex?.firstMatch(in: line, options: [],