freshOS / Localize

🏁 Automatically clean your Localizable.strings files
MIT License
354 stars 29 forks source link

Would be great to support SwiftGen #1

Closed JuliusBahr closed 7 years ago

JuliusBahr commented 7 years ago

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 7 years ago

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

JuliusBahr commented 7 years ago

No definitely not: git push origin feature/supportSwiftGen:feature/supportSwiftGen remote: Permission to freshOS/Localize.git denied to JuliusBahr. fatal: unable to access 'https://github.com/freshOS/Localize.git/': The requested URL returned error: 403

On 28 Mar 2017, at 15:54, S4cha notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/freshOS/Localize/issues/1#issuecomment-289777162, or mute the thread https://github.com/notifications/unsubscribe-auth/AQeZQCTfQ5nx6po259-G8nBZK0vWDNVjks5rqREhgaJpZM4MrkyV.

maxkonovalov commented 7 years ago

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 7 years ago

@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?

JuliusBahr commented 7 years ago

yep, please go ahead and thanks

On 13. Apr 2017, at 11:37, S4cha notifications@github.com wrote:

@JuliusBahr https://github.com/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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/freshOS/Localize/issues/1#issuecomment-293841568, or mute the thread https://github.com/notifications/unsubscribe-auth/AQeZQMnKWia6Fil5VIdsU1-vEFAb60eIks5rvezzgaJpZM4MrkyV.

s4cha commented 7 years ago

@JuliusBahr the patch has been applied : https://github.com/freshOS/Localize/commit/9be6923918ab9a671c049f7e682e89c47212957a

s4cha commented 7 years ago

Thanks a lot :)