Skip to content

Commit

Permalink
Version 3.35.0
Browse files Browse the repository at this point in the history
  • Loading branch information
webim committed Jun 15, 2021
1 parent 9cd1233 commit bcbdf89
Show file tree
Hide file tree
Showing 122 changed files with 4,352 additions and 2,190 deletions.
2 changes: 2 additions & 0 deletions Example/Localizer/AdditionalKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
// MARK: - Remote notifications
// "P.OA".localized
// "P.OF".localized
// "P.RO".localized
// "P.CR".localized
// "P.OM".localized
24 changes: 21 additions & 3 deletions Example/Localizer/ProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ProjectParser: NSObject {
static func updateXibTranslations(projectFolderPath: String, xibKeysMap: XibFileData, translations: Translations, xibTranslations: XibTranslations ) {
let stringsFiles = StringsFileParser.filesList(inFolder: projectFolderPath, withSuffix: ".strings")
for filePath in stringsFiles {
if !filePath.hasSuffix("Localizable.strings") && !filePath.hasSuffix("InfoPlist.strings"){
if !filePath.hasSuffix("Localizable.strings") && !filePath.hasSuffix("InfoPlist.strings") {

let locale = filePath.getLocale()
let filename = filePath.nameWithoutExtension().lastPathComponent
Expand All @@ -94,7 +94,6 @@ class ProjectParser: NSObject {
}
fileString.writeToFile(filePath)
}

}
}

Expand All @@ -104,7 +103,6 @@ class ProjectParser: NSObject {
let stringsFiles = StringsFileParser.filesList(inFolder: projectFolderPath, withSuffix: "Localizable.strings")
for filePath in stringsFiles.reversed() {

print(filePath)
let locale = filePath.getLocale()

let text = ShellWrapper.readUTF8File(filePath)
Expand Down Expand Up @@ -161,11 +159,31 @@ class ProjectParser: NSObject {
}
}

static func checkLocalizationForEveryUIFile(_ projectFolderPath: String, files: [String]) {
let ignoredUIFiles = ["LaunchScreen", "LaunchScreenController"]
let stringsFiles = StringsFileParser.filesList(inFolder: projectFolderPath, withSuffix: ".strings")

for file in files {

if file.nameWithoutExtension().lastPathComponent.presentAsSuffixInArray(ignoredUIFiles) {
continue
}

if !("/" + file.nameWithoutExtension().lastPathComponent + ".strings").presentAsSuffixInArray(stringsFiles) {
print("!!! file not localized \(file) ")
fatalError()
}

}
}

static func getAllXibKeys(projectFolderPath: String, codeKeys: inout [CodeKey: [FileName]], xibKeysMap: inout XibFileData) {
let xibFiles = StringsFileParser.filesList(inFolder: projectFolderPath, withSuffix: ".xib")
let storyboardFiles = StringsFileParser.filesList(inFolder: projectFolderPath, withSuffix: ".storyboard")
let UIFiles = xibFiles + storyboardFiles

self.checkLocalizationForEveryUIFile(projectFolderPath, files: UIFiles)

for file in UIFiles {

let xibKeys = StringsFileParser.getXibKeysFromFile(filePath: file)
Expand Down
13 changes: 13 additions & 0 deletions Example/Localizer/String+LocalizationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,17 @@ extension String {
print("Failed writing to URL: \(fileUrl), Error: " + error.localizedDescription)
}
}

func contains(find: String) -> Bool {
return self.range(of: find) != nil
}

func presentAsSuffixInArray(_ strings: [String]) -> Bool {
for string in strings {
if string.hasSuffix(self) {
return true
}
}
return false
}
}
39 changes: 39 additions & 0 deletions Example/Localizer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,42 @@ if CommandLine.arguments.count >= 2 {
} else {
print("project path not found")
}
/*
Пример использования утилиты для локализации проекта
в проект добавлен новый target - Localizer
при его запуске он пройдет по всем .swift .storyboard и .xib файлам, найдет в них значения которые надо локализовать и добавит их в Localizable.strings и .strings файлы относящиеся к UI

////////
как это работает для значений в коде
мы вносим изменения в код, скажем добавляем алерт с текстом "My new message" .localized
перед коммитом мы запускаем target - Localizer и он добавляет новое значение в каждый из Localizable.strings файлов, т.е. в них появятся строки вроде

//RatingDialogViewController.swift
"My new message" = "My new message";

меняем в файле для русской локали строку на
"My new message" = "Мое новое сообщение";
готово, можно коммитить.

////////
как это работает для значений в storyboard и xib
добавляем новую кнопку в IB с текстом "My new button"
перед коммитом мы запускаем target - Localizer и он добавляет новое значение в каждый из Localizable.strings файлов, и в ConnectionErrorView.strings

при этом для каждой локали в Localizable.strings появится
//ConnectionErrorView.xib
"My new button" = "My new button";

а в ConnectionErrorView.strings
"fGs-8a-dfc.text" = "My new button";

мы меняем ТОЛЬКО значение в Localizable.strings на
"My new button" = "Моя новая кнопка";
еще раз запускаем Localizer. Готово, можно коммитить
значение в ConnectionErrorView.strings будет обновлено автоматически

плюсы, при таком подходе
мы не можем пропустить какое либо не локализованное значение
мы не создаем новые енумы и убираем дублирование переводов
нам не нужно совершать дополнительные действия в IB чтобы локализовать текст
*/
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target 'WebimClientLibrary_Example' do
pod 'SlackTextViewController', :inhibit_warnings => true
pod 'SnapKit', :inhibit_warnings => true
pod 'SQLite.swift', '0.12.2', :inhibit_warnings => true # WebimClientLibrary dependency – added to inhibit its warnings.
pod 'Nuke', '~> 8.0'
pod 'Nuke', '~> 8.0', :inhibit_warnings => true

target 'WebimClientLibrary_Tests' do
inherit! :search_paths
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ PODS:
- SQLite.swift (0.12.2):
- SQLite.swift/standard (= 0.12.2)
- SQLite.swift/standard (0.12.2)
- WebimClientLibrary (3.34.6):
- WebimClientLibrary (3.35.0):
- SQLite.swift (= 0.12.2)

DEPENDENCIES:
Expand Down Expand Up @@ -151,8 +151,8 @@ SPEC CHECKSUMS:
SlackTextViewController: b854e62c1c156336bc4fd409c6ca79b5773e8f9d
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
SQLite.swift: d2b4642190917051ce6bd1d49aab565fe794eea3
WebimClientLibrary: 8d4713a068406ccb72704e2654a29f95236baa6f
WebimClientLibrary: 8ba6e754c52846c3194531cf8c889116e944ced2

PODFILE CHECKSUM: 26a5269aabefcf0054dd666b1450b78d5f6158d3
PODFILE CHECKSUM: a4d281ecdc6f8dea2a6ccfe87b3789dd77cf6683

COCOAPODS: 1.10.1
2 changes: 1 addition & 1 deletion Example/Tests/MessageHolderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class MessageHolderTests: XCTestCase {
queue: DispatchQueue.global(qos: .userInteractive))
let actionRequestLoop = ActionRequestLoop(completionHandlerExecutor: execIfNotDestroyedHandlerExecutor,
internalErrorListener: InternalErrorListenerForTests())
let webimActions = WebimActions(baseURL: MessageImplMockData.serverURLString.rawValue,
let webimActions = WebimActionsImpl(baseURL: MessageImplMockData.serverURLString.rawValue,
actionRequestLoop: actionRequestLoop)
let remoteHistoryProvider = RemoteHistoryProviderForTests(withWebimActions: webimActions,
historyMessageMapper: HistoryMessageMapper(withServerURLString: MessageImplMockData.serverURLString.rawValue),
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/MessageStreamImplTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MessageStreamImplTests: XCTestCase {
let accessChecker = AccessChecker(thread: Thread.current,
sessionDestroyer: sessionDestroyer)
let queue = DispatchQueue.main
webimActions = WebimActions(baseURL: serverURLString,
webimActions = WebimActionsImpl(baseURL: serverURLString,
actionRequestLoop: ActionRequestLoopForTests(completionHandlerExecutor: ExecIfNotDestroyedHandlerExecutor(sessionDestroyer: sessionDestroyer,
queue: queue),
internalErrorListener: InternalErrorListenerForTests()))
Expand Down
Loading

0 comments on commit bcbdf89

Please sign in to comment.