From 36f30b67c8d14cc928784e78a28d05f8b96c3918 Mon Sep 17 00:00:00 2001 From: Andres Silva Gomez Date: Tue, 15 May 2018 08:54:05 -0500 Subject: [PATCH] Fix Locale keys only with one string file. --- CHANGELOG.md | 10 +++++++++- Localize.podspec | 4 ++-- Localize.xcodeproj/project.pbxproj | 8 ++++++++ README.md | 2 +- Source/LocalizeStrings.swift | 8 ++++++++ Tests/OnlyOneLang.strings | 1 + Tests/StringBaseTest.swift | 2 -- Tests/StringSingleTest.swift | 29 +++++++++++++++++++++++++++++ 8 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Tests/OnlyOneLang.strings create mode 100644 Tests/StringSingleTest.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 6739519..f007f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,21 @@ All notable changes to this project will be documented in this file. `Localize` adheres to [Semantic Versioning](http://semver.org/). +## [2.0.3](https://github.com/andresilvagomez/Localize/releases/tag/2.0.3) +Released on 2018-05-15. + +#### Added +- Fix localize strings when user only has a one string file. + - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request + [#27](https://github.com/andresilvagomez/Localize/pull/27). + ## [2.0.2](https://github.com/andresilvagomez/Localize/releases/tag/2.0.2) Released on 2018-05-10. #### Added - Improve strings with extended languajes like to es-mx for defaults localizations. - By [Benjamin Erhart](https://github.com/tladesignz) in Pull Request - [#24](https://github.com/andresilvagomez/Localize/pull/25). + [#25](https://github.com/andresilvagomez/Localize/pull/25). ## [2.0.1](https://github.com/andresilvagomez/Localize/releases/tag/2.0.1) Released on 2018-04-15. diff --git a/Localize.podspec b/Localize.podspec index a3a8d78..382285c 100644 --- a/Localize.podspec +++ b/Localize.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "Localize" - s.version = "2.0.2" + s.version = "2.0.3" s.license = 'MIT' s.summary = "Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings." s.homepage = "https://github.com/andresilvagomez/Localize" s.author = { "Andres Silva" => "andresilvagomez@gmail.com" } - s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.0.2" } + s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.0.3" } s.ios.deployment_target = '9.0' s.source_files = "Source/*.swift" diff --git a/Localize.xcodeproj/project.pbxproj b/Localize.xcodeproj/project.pbxproj index f6aa702..72e50bf 100644 --- a/Localize.xcodeproj/project.pbxproj +++ b/Localize.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 2B41FFEB20AB19570012AF1E /* StringSingleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B41FFEA20AB19570012AF1E /* StringSingleTest.swift */; }; + 2B41FFEC20AB1A450012AF1E /* OnlyOneLang.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2B41FFE820AB18FE0012AF1E /* OnlyOneLang.strings */; }; 2B717465207D9AFE0070DC5F /* LocalizeUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B717464207D9AFE0070DC5F /* LocalizeUI.swift */; }; 2B717469207DC6E00070DC5F /* UIViewComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B717468207DC6E00070DC5F /* UIViewComponents.swift */; }; 2B931AA8208302FB00C26D6B /* lang-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 9F761AEB1E3063E400904B4B /* lang-en.json */; }; @@ -56,6 +58,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 2B41FFE820AB18FE0012AF1E /* OnlyOneLang.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = OnlyOneLang.strings; sourceTree = ""; }; + 2B41FFEA20AB19570012AF1E /* StringSingleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringSingleTest.swift; sourceTree = ""; }; 2B717464207D9AFE0070DC5F /* LocalizeUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizeUI.swift; sourceTree = ""; }; 2B717468207DC6E00070DC5F /* UIViewComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewComponents.swift; sourceTree = ""; }; 2B80F11B20830FBD00542924 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Storyboard.strings; sourceTree = ""; }; @@ -176,6 +180,7 @@ 9FA3BC501E318C080054CA92 /* ReadingOtherFiles.swift */, 2BD8531820812DD900FB0E53 /* StringBadSources.swift */, 9F19DFC61E4D2B1D00F953E6 /* StringBaseTest.swift */, + 2B41FFEA20AB19570012AF1E /* StringSingleTest.swift */, 9F1678001E51F33E0022F3F8 /* StringBaseTestInSpanish.swift */, 9FCD8EA41E52AD3E00B5909C /* StringsChanginDefaultFileName.swift */, 2B717468207DC6E00070DC5F /* UIViewComponents.swift */, @@ -202,6 +207,7 @@ 9F1677FC1E51DE270022F3F8 /* Strings.strings */, 9FCD8EA21E52A9D800B5909C /* Other.strings */, 2BD85322208130A100FB0E53 /* Storyboard.storyboard */, + 2B41FFE820AB18FE0012AF1E /* OnlyOneLang.strings */, ); name = "Supporting Files"; sourceTree = ""; @@ -316,6 +322,7 @@ 2B931AAD2083031000C26D6B /* some-it.json in Resources */, 2B931AB02083031700C26D6B /* Strings.strings in Resources */, 2B931AAE2083031000C26D6B /* file-de.json in Resources */, + 2B41FFEC20AB1A450012AF1E /* OnlyOneLang.strings in Resources */, 2B931AAC2083031000C26D6B /* other-es.json in Resources */, 2B931AB12083031700C26D6B /* Other.strings in Resources */, 2B931AA8208302FB00C26D6B /* lang-en.json in Resources */, @@ -349,6 +356,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2B41FFEB20AB19570012AF1E /* StringSingleTest.swift in Sources */, 2B717469207DC6E00070DC5F /* UIViewComponents.swift in Sources */, 9F1678011E51F33E0022F3F8 /* StringBaseTestInSpanish.swift in Sources */, 9F989F4C1E2B3B8200A19F67 /* BaseTest.swift in Sources */, diff --git a/README.md b/README.md index 31e1014..be11d0c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ platform :ios, '9.0' use_frameworks! target '' do - pod 'Localize' , '~> 2.0.2' + pod 'Localize' , '~> 2.0.3' end ``` diff --git a/Source/LocalizeStrings.swift b/Source/LocalizeStrings.swift index 39c9ded..9bca3aa 100644 --- a/Source/LocalizeStrings.swift +++ b/Source/LocalizeStrings.swift @@ -88,6 +88,14 @@ class LocalizeStrings: LocalizeCommonProtocol { return localized } } + + if bundle.path(forResource: tableName, ofType: "strings") != nil { + let localized = bundle.localizedString(forKey: key, value: nil, table: tableName) + + if localized != key { + return localized + } + } return nil } diff --git a/Tests/OnlyOneLang.strings b/Tests/OnlyOneLang.strings new file mode 100644 index 0000000..e396d3e --- /dev/null +++ b/Tests/OnlyOneLang.strings @@ -0,0 +1 @@ +"hello.world.for.all" = "Hello world for all"; diff --git a/Tests/StringBaseTest.swift b/Tests/StringBaseTest.swift index e10510f..148828c 100644 --- a/Tests/StringBaseTest.swift +++ b/Tests/StringBaseTest.swift @@ -9,7 +9,6 @@ import XCTest import Localize class StringBaseTest: XCTestCase { - override func setUp() { super.setUp() Localize.update(provider: .strings) @@ -61,5 +60,4 @@ class StringBaseTest: XCTestCase { let language = Localize.currentLanguage XCTAssertTrue(language == "en") } - } diff --git a/Tests/StringSingleTest.swift b/Tests/StringSingleTest.swift new file mode 100644 index 0000000..24f8ffb --- /dev/null +++ b/Tests/StringSingleTest.swift @@ -0,0 +1,29 @@ +// +// StringSingleTest.swift +// LocalizeTests +// +// Created by Andres Silva Gomez on 5/15/18. +// Copyright © 2018 Kekiiwaa. All rights reserved. +// + +import XCTest +import Localize + +class StringSingleTest: XCTestCase { + override func setUp() { + super.setUp() + Localize.update(provider: .strings) + Localize.update(bundle: Bundle(for: type(of: self))) + Localize.update(fileName: "OnlyOneLang") + } + + func testLocalizeInSingleStringFile() { + let localized = "hello.world.for.all".localized + XCTAssertTrue(localized == "Hello world for all") + } + + func testLocalizeInSingleStringFileNil() { + let localized = "hello.world.for.allll".localized + XCTAssertTrue(localized == "hello.world.for.allll") + } +}