Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Example/LocalizeExample/LocalizeExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
9946306A1FAC68410004A9A2 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +85,7 @@
isa = PBXGroup;
children = (
99EB549A1FAC6D3300AD728C /* Localizable.strings */,
2768922D25915C5600F439FA /* Localizable.swift */,
);
path = Languages;
sourceTree = "<group>";
Expand Down Expand Up @@ -115,7 +118,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = freshos;
TargetAttributes = {
994630641FAC68410004A9A2 = {
Expand Down Expand Up @@ -178,6 +181,7 @@
buildActionMask = 2147483647;
files = (
9946306B1FAC68410004A9A2 /* ViewController.swift in Sources */,
2768922E25915C5600F439FA /* Localizable.swift in Sources */,
994630691FAC68410004A9A2 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -213,15 +217,18 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand All @@ -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;
Expand All @@ -271,15 +278,18 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
24 changes: 24 additions & 0 deletions Example/LocalizeExample/Resources/Languages/Localizable.swift
Original file line number Diff line number Diff line change
@@ -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: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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";
1 change: 1 addition & 0 deletions Example/LocalizeExample/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
9 changes: 6 additions & 3 deletions Localize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

/*
Expand Down Expand Up @@ -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: [],
Expand Down