freshOS/Localize

Would be great to support SwiftGen

JuliusBahr opened this issue · 7 comments

Hey
we use SwiftGen in our code base and I would like to use Localize too.
I have created a patch that adds SwiftGen support and adds additional logging. Unfortunately I have no rights to create a PR, so I will paste below.
With best regards

Julius

diff --git a/Localize.swift b/Localize.swift
index 7f05cf6..de82525 100755
--- a/Localize.swift
+++ b/Localize.swift
@@ -26,7 +26,8 @@ let relativeSourceFolder = ""
  */
 let patterns = [
     "NSLocalizedString\\(@?\"(\\w+)\"", // Swift and Objc Native
-    "Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)" // Laurine Calls
+    "Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)", // Laurine Calls
+    "L10n.tr\\(key: \"(\\w+)\""// SwiftGen generation
 ]
 
 /*
@@ -64,8 +65,13 @@ let masterLanguage = "en"
 func listSupportedLanguages() -> [String] {
     var sl = [String]()
     let path = FileManager.default.currentDirectoryPath + relativeLocalizableFolders
+    if !FileManager.default.fileExists(atPath: path) {
+        print("Invalid configuration: \(path) does not exist.")
+        exit(1)
+    }
     let enumerator: FileManager.DirectoryEnumerator? = FileManager.default.enumerator(atPath: path)
     let extensionName = "lproj"
+    print("Found these languages:")
     while let element = enumerator?.nextObject() as? String {
         if element.hasSuffix(extensionName) {
:...skipping...
diff --git a/Localize.swift b/Localize.swift
index 7f05cf6..de82525 100755
--- a/Localize.swift
+++ b/Localize.swift
@@ -26,7 +26,8 @@ let relativeSourceFolder = ""
  */
 let patterns = [
     "NSLocalizedString\\(@?\"(\\w+)\"", // Swift and Objc Native
-    "Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)" // Laurine Calls
+    "Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)", // Laurine Calls
+    "L10n.tr\\(key: \"(\\w+)\""// SwiftGen generation
 ]
 
 /*
@@ -64,8 +65,13 @@ let masterLanguage = "en"
 func listSupportedLanguages() -> [String] {
     var sl = [String]()
     let path = FileManager.default.currentDirectoryPath + relativeLocalizableFolders
+    if !FileManager.default.fileExists(atPath: path) {
+        print("Invalid configuration: \(path) does not exist.")
+        exit(1)
+    }
     let enumerator: FileManager.DirectoryEnumerator? = FileManager.default.enumerator(atPath: path)
     let extensionName = "lproj"
+    print("Found these languages:")
     while let element = enumerator?.nextObject() as? String {
         if element.hasSuffix(extensionName) {
             print(element)
s4cha commented

@JuliusBahr
How come you don't have PR rights? That is a very welcome addition :)

Hi @JuliusBahr, to submit a PR you need to fork the repo first, and then push the changes to a branch on your own repo.
Hope this helps ;)

s4cha commented

@JuliusBahr if you don't feel like making a PR we can update it ourselves based on the diff you provided and mention you :) What do you think?

s4cha commented

@JuliusBahr the patch has been applied :
9be6923

s4cha commented

Thanks a lot :)