Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for comments #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Sources/Localize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public extension String {
Swift 2 friendly localization syntax, replaces NSLocalizedString
- Returns: The localized string.
*/
func localized() -> String {
func localized(comment: String = "") -> String {
if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) {
return bundle.localizedStringForKey(self, value: nil, table: nil)
}
Expand Down
4 changes: 4 additions & 0 deletions genstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def fetch_files_recursive(directory, extension):
localizedStringNil = re.compile('NSLocalizedString\("([^"]*)",\s*nil\s*\)', re.DOTALL)
localized = re.compile('Localized\("([^"]*)"[^\n\r]*\)', re.DOTALL)
localizedSwift2 = re.compile('"([^"]*)".localized\(\)', re.DOTALL)
localizedSwift2Comment = re.compile('"([^"]*)".localized\(\s*"([^"]*)"\s*\)', re.DOTALL)
localizedSwift2WithFormat = re.compile('"([^"]*)".localizedFormat\([^\n\r]*\)', re.DOTALL)

# get string list
Expand All @@ -62,6 +63,9 @@ def fetch_files_recursive(directory, extension):
for result in localizedSwift2.finditer(content):
uid += 1
strings.append((result.group(1), '', file, uid))
for result in localizedSwift2Comment.finditer(content):
uid += 1
strings.append((result.group(1), result.group(2), file, uid))
for result in localizedSwift2WithFormat.finditer(content):
uid += 1
strings.append((result.group(1), '', file, uid))
Expand Down