From c3435e433bd13cc8a0ce3aaa94257f8ece63a859 Mon Sep 17 00:00:00 2001 From: Andres Silva Gomez Date: Sun, 15 Apr 2018 20:12:22 -0500 Subject: [PATCH] Fix travis with cocoapods test and local test. code coverage 99+ and little details --- .swift-version | 2 +- CHANGELOG.md | 57 ++++++++++++------- Localize.podspec | 5 +- Localize.xcodeproj/project.pbxproj | 55 +++++++++++------- .../xcshareddata/xcschemes/Localize.xcscheme | 1 + README.md | 6 +- Source/Localize.swift | 6 -- Source/LocalizeCommonProtocol.swift | 27 ++++----- Source/LocalizeJson.swift | 4 +- Source/LocalizeProtocol.swift | 7 --- Source/LocalizeStatic.swift | 6 -- Source/LocalizeStrings.swift | 4 +- Tests/BaseTest.swift | 14 ++++- Tests/BaseTestInSpanish.swift | 10 +++- Tests/JSONBadSources.swift | 2 +- Tests/JsonChanginFileName.swift | 2 +- Tests/OtherLangTest.swift | 2 +- Tests/ReadingOtherFiles.swift | 6 +- Tests/StringBadSources.swift | 2 +- Tests/StringBaseTest.swift | 4 +- Tests/StringBaseTestInSpanish.swift | 4 +- Tests/StringsChanginDefaultFileName.swift | 2 +- Tests/UIViewComponents.swift | 2 +- Tests/UIViewComponentsES.swift | 2 +- Tests/UIViewComponentsWithString.swift | 2 +- Tests/fr.lproj/Storyboard.storyboard | 7 --- Tests/fr.lproj/Storyboard.strings | 1 + Tests/lang-fr.json | 25 ++++++++ 28 files changed, 153 insertions(+), 114 deletions(-) delete mode 100644 Tests/fr.lproj/Storyboard.storyboard create mode 100644 Tests/fr.lproj/Storyboard.strings create mode 100644 Tests/lang-fr.json diff --git a/.swift-version b/.swift-version index 5186d07..7d5c902 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9598d78..786318b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,20 @@ All notable changes to this project will be documented in this file. `Localize` adheres to [Semantic Versioning](http://semver.org/). -## [2.0.0](https://github.com/kekiiwaa/Localize/releases/tag/2.0.0) +## [2.0.1](https://github.com/andresilvagomez/Localize/releases/tag/2.0.1) +Released on 2018-04-15. + +#### Added +- Include testing with cocoapods. +- Code coverage 99+. +- General changes to improve test. +- Included in awesome ios. + - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request + [#23](https://github.com/andresilvagomez/Localize/pull/23). + +--- + +## [2.0.0](https://github.com/andresilvagomez/Localize/releases/tag/2.0.0) Released on 2018-04-12. #### Added @@ -14,63 +27,63 @@ Released on 2018-04-12. - Segment controls localize key using "," and base. - UIView components tested. - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#22](https://github.com/Kekiiwaa/Localize/pull/22). + [#22](https://github.com/andresilvagomez/Localize/pull/22). --- -## [1.5.2](https://github.com/kekiiwaa/Localize/releases/tag/1.5.2) +## [1.5.2](https://github.com/andresilvagomez/Localize/releases/tag/1.5.2) Released on 2017-09-27. #### Added - Swift 4. - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#18](https://github.com/Kekiiwaa/Localize/pull/18). + [#18](https://github.com/andresilvagomez/Localize/pull/18). --- -## [1.5.1](https://github.com/kekiiwaa/Localize/releases/tag/1.5.1) +## [1.5.1](https://github.com/andresilvagomez/Localize/releases/tag/1.5.1) Released on 2017-08-10. #### Added - Fix with country code. - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#17](https://github.com/Kekiiwaa/Localize/pull/17). + [#17](https://github.com/andresilvagomez/Localize/pull/17). --- -## [1.5.0](https://github.com/kekiiwaa/Localize/releases/tag/1.5.0) +## [1.5.0](https://github.com/andresilvagomez/Localize/releases/tag/1.5.0) Released on 2017-08-08. #### Added - Localize UI elements with @IBInspectable. - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#14](https://github.com/Kekiiwaa/Localize/pull/14). + [#14](https://github.com/andresilvagomez/Localize/pull/14). #### Deleted - Delete custom classes for UI elements in favor to @IBInspectable extensions. - By [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#14](https://github.com/Kekiiwaa/Localize/pull/14). + [#14](https://github.com/andresilvagomez/Localize/pull/14). --- -## [1.4.0](https://github.com/kekiiwaa/Localize/releases/tag/1.4.0) +## [1.4.0](https://github.com/andresilvagomez/Localize/releases/tag/1.4.0) Released on 2017-07-10. #### Added - Dynamic bundle. - Update bundle. - Added by [Benjamin Erhart](https://github.com/tladesignz) in Pull Request - [#13](https://github.com/Kekiiwaa/Localize/pull/13). + [#13](https://github.com/andresilvagomez/Localize/pull/13). #### Updated - Remove enums for language. - Fixed #localize with placeholder replacement. - Added by [Benjamin Erhart](https://github.com/tladesignz) in Pull Request - [#13](https://github.com/kekiiwaa/Localize/pull/13). + [#13](https://github.com/andresilvagomez/Localize/pull/13). --- -## [1.3.0](https://github.com/kekiiwaa/Localize/releases/tag/1.3.0) +## [1.3.0](https://github.com/andresilvagomez/Localize/releases/tag/1.3.0) Released on 2017-02-14. #### Added @@ -80,17 +93,17 @@ Released on 2017-02-14. - Testing mode. - 100% documented using jazzy. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#8](https://github.com/kekiiwaa/Localize/pull/4). + [#8](https://github.com/andresilvagomez/Localize/pull/4). #### Updated - Not use vars to config. - Delete cache json file. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#8](https://github.com/kekiiwaa/Localize/pull/4). + [#8](https://github.com/andresilvagomez/Localize/pull/4). --- -## [1.2.0](https://github.com/kekiiwaa/Localize/releases/tag/1.2.0) +## [1.2.0](https://github.com/andresilvagomez/Localize/releases/tag/1.2.0) Released on 2017-01-19. #### Added @@ -100,22 +113,22 @@ Released on 2017-01-19. - Testing mode. - Testing for more methods and cases. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#4](https://github.com/kekiiwaa/Localize/pull/4). + [#4](https://github.com/andresilvagomez/Localize/pull/4). #### Updated - Config methods. - Statics calleds. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#4](https://github.com/kekiiwaa/Localize/pull/4). + [#4](https://github.com/andresilvagomez/Localize/pull/4). #### Fixed - Getting default language key when in current language key no was available. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#4](https://github.com/kekiiwaa/Localize/pull/4). + [#4](https://github.com/andresilvagomez/Localize/pull/4). --- -## [1.1](https://github.com/kekiiwaa/Localize/releases/tag/1.1) +## [1.1](https://github.com/andresilvagomez/Localize/releases/tag/1.1) Released on 2017-01-17. #### Added @@ -126,9 +139,9 @@ Released on 2017-01-17. - Notification when user change a language. - Update all localized components when user change language. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#2](https://github.com/kekiiwaa/Localize/pull/2). + [#2](https://github.com/andresilvagomez/Localize/pull/2). #### Updated - Updated Example. - Added by [Andres Silva](https://github.com/andresilvagomez) in Pull Request - [#2](https://github.com/kekiiwaa/Localize/pull/2). + [#2](https://github.com/andresilvagomez/Localize/pull/2). diff --git a/Localize.podspec b/Localize.podspec index 1cc6d25..a400797 100644 --- a/Localize.podspec +++ b/Localize.podspec @@ -1,18 +1,19 @@ Pod::Spec.new do |s| s.name = "Localize" - s.version = "2.0.0" + s.version = "2.0.1" 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.0" } + s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.0.1" } s.ios.deployment_target = '9.0' s.source_files = "Source/*.swift" s.test_spec 'Localize' do |test_spec| test_spec.source_files = 'Tests/*.swift' + test_spec.resources = 'Tests/*.{json,lproj}' end end diff --git a/Localize.xcodeproj/project.pbxproj b/Localize.xcodeproj/project.pbxproj index 33b6f51..8ec7b47 100644 --- a/Localize.xcodeproj/project.pbxproj +++ b/Localize.xcodeproj/project.pbxproj @@ -9,23 +9,29 @@ /* Begin PBXBuildFile section */ 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 */; }; + 2B931AA92083030400C26D6B /* langTable-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 2BD853262081316E00FB0E53 /* langTable-en.json */; }; + 2B931AAA2083030700C26D6B /* lang-es.json in Resources */ = {isa = PBXBuildFile; fileRef = 9F4570211E3173A4008C37D1 /* lang-es.json */; }; + 2B931AAB2083031000C26D6B /* other-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4A1E318BCB0054CA92 /* other-en.json */; }; + 2B931AAC2083031000C26D6B /* other-es.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA61E53319900B5909C /* other-es.json */; }; + 2B931AAD2083031000C26D6B /* some-it.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4C1E318BDC0054CA92 /* some-it.json */; }; + 2B931AAE2083031000C26D6B /* file-de.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4E1E318BED0054CA92 /* file-de.json */; }; + 2B931AAF2083031000C26D6B /* badJSON-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 2BD853282081330600FB0E53 /* badJSON-en.json */; }; + 2B931AB02083031700C26D6B /* Strings.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9F1677FC1E51DE270022F3F8 /* Strings.strings */; }; + 2B931AB12083031700C26D6B /* Other.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA21E52A9D800B5909C /* Other.strings */; }; + 2B931AB22083031700C26D6B /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2BD85322208130A100FB0E53 /* Storyboard.storyboard */; }; 2BAA7AA4207FC9F6008E4E3A /* UIViewComponentsES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BAA7AA3207FC9F6008E4E3A /* UIViewComponentsES.swift */; }; 2BAA7AA6207FCA8B008E4E3A /* UIViewComponentsWithString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BAA7AA5207FCA8B008E4E3A /* UIViewComponentsWithString.swift */; }; + 2BB606BA2083120F00DFEF11 /* lang-fr.json in Resources */ = {isa = PBXBuildFile; fileRef = 2BB606B82083119100DFEF11 /* lang-fr.json */; }; 2BD8531920812DD900FB0E53 /* StringBadSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD8531820812DD900FB0E53 /* StringBadSources.swift */; }; 2BD8531B20812EBD00FB0E53 /* JSONBadSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD8531A20812EBD00FB0E53 /* JSONBadSources.swift */; }; - 2BD85320208130A100FB0E53 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2BD85322208130A100FB0E53 /* Storyboard.storyboard */; }; - 2BD853272081316E00FB0E53 /* langTable-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 2BD853262081316E00FB0E53 /* langTable-en.json */; }; - 2BD853292081330600FB0E53 /* badJSON-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 2BD853282081330600FB0E53 /* badJSON-en.json */; }; - 9F1677FA1E51DE270022F3F8 /* Strings.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9F1677FC1E51DE270022F3F8 /* Strings.strings */; }; 9F1678011E51F33E0022F3F8 /* StringBaseTestInSpanish.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F1678001E51F33E0022F3F8 /* StringBaseTestInSpanish.swift */; }; 9F19DFC71E4D2B1D00F953E6 /* StringBaseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F19DFC61E4D2B1D00F953E6 /* StringBaseTest.swift */; }; 9F262D911E525565002DD75A /* LocalizeCommonProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F262D901E525565002DD75A /* LocalizeCommonProtocol.swift */; }; 9F2FC5651E4275A300C15610 /* LocalizeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F2FC5641E4275A300C15610 /* LocalizeProtocol.swift */; }; 9F2FC5671E42793B00C15610 /* LocalizeJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F2FC5661E42793B00C15610 /* LocalizeJson.swift */; }; 9F2FC5691E427AFD00C15610 /* LocalizeStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F2FC5681E427AFD00C15610 /* LocalizeStrings.swift */; }; - 9F4570221E3173A4008C37D1 /* lang-es.json in Resources */ = {isa = PBXBuildFile; fileRef = 9F4570211E3173A4008C37D1 /* lang-es.json */; }; 9F761AD71E305B9B00904B4B /* LocalizeStatic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F761AD61E305B9B00904B4B /* LocalizeStatic.swift */; }; - 9F761AEC1E3063E400904B4B /* lang-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 9F761AEB1E3063E400904B4B /* lang-en.json */; }; 9F93453F1E29192300C400F7 /* LocalizeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F93453A1E29192300C400F7 /* LocalizeExtensions.swift */; }; 9F9345411E29192300C400F7 /* Localize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F93453C1E29192300C400F7 /* Localize.swift */; }; 9F9345421E29192300C400F7 /* LocalizeString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F93453D1E29192300C400F7 /* LocalizeString.swift */; }; @@ -34,13 +40,8 @@ 9F989F4C1E2B3B8200A19F67 /* BaseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F989F411E2B34E700A19F67 /* BaseTest.swift */; }; 9F989F4D1E2B3B8300A19F67 /* OtherLangTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F989F441E2B34E700A19F67 /* OtherLangTest.swift */; }; 9FA3BC491E3174980054CA92 /* BaseTestInSpanish.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FA3BC481E3174980054CA92 /* BaseTestInSpanish.swift */; }; - 9FA3BC4B1E318BCB0054CA92 /* other-en.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4A1E318BCB0054CA92 /* other-en.json */; }; - 9FA3BC4D1E318BDC0054CA92 /* some-it.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4C1E318BDC0054CA92 /* some-it.json */; }; - 9FA3BC4F1E318BED0054CA92 /* file-de.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FA3BC4E1E318BED0054CA92 /* file-de.json */; }; 9FA3BC511E318C080054CA92 /* ReadingOtherFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FA3BC501E318C080054CA92 /* ReadingOtherFiles.swift */; }; - 9FCD8EA01E52A9D800B5909C /* Other.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA21E52A9D800B5909C /* Other.strings */; }; 9FCD8EA51E52AD3E00B5909C /* StringsChanginDefaultFileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA41E52AD3E00B5909C /* StringsChanginDefaultFileName.swift */; }; - 9FCD8EA71E53319900B5909C /* other-es.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA61E53319900B5909C /* other-es.json */; }; 9FCD8EA91E53327D00B5909C /* JsonChanginFileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FCD8EA81E53327D00B5909C /* JsonChanginFileName.swift */; }; /* End PBXBuildFile section */ @@ -57,8 +58,12 @@ /* Begin PBXFileReference section */ 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 = ""; }; + 2B80F11C20830FBD00542924 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Strings.strings; sourceTree = ""; }; + 2B80F11D20830FBD00542924 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Other.strings; sourceTree = ""; }; 2BAA7AA3207FC9F6008E4E3A /* UIViewComponentsES.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewComponentsES.swift; sourceTree = ""; }; 2BAA7AA5207FCA8B008E4E3A /* UIViewComponentsWithString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewComponentsWithString.swift; sourceTree = ""; }; + 2BB606B82083119100DFEF11 /* lang-fr.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "lang-fr.json"; sourceTree = ""; }; 2BD8531820812DD900FB0E53 /* StringBadSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringBadSources.swift; sourceTree = ""; }; 2BD8531A20812EBD00FB0E53 /* JSONBadSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONBadSources.swift; sourceTree = ""; }; 2BD85325208130B400FB0E53 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Storyboard.storyboard; sourceTree = ""; }; @@ -184,6 +189,7 @@ 9F989F4A1E2B3B5600A19F67 /* Supporting Files */ = { isa = PBXGroup; children = ( + 2BB606B82083119100DFEF11 /* lang-fr.json */, 9F761AEB1E3063E400904B4B /* lang-en.json */, 2BD853262081316E00FB0E53 /* langTable-en.json */, 9F4570211E3173A4008C37D1 /* lang-es.json */, @@ -280,6 +286,7 @@ en, es, Base, + fr, ); mainGroup = 69F1B56A1D955990000A2B87; productRefGroup = 69F1B5751D955990000A2B87 /* Products */; @@ -297,17 +304,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9FA3BC4F1E318BED0054CA92 /* file-de.json in Resources */, - 9FCD8EA71E53319900B5909C /* other-es.json in Resources */, - 2BD853292081330600FB0E53 /* badJSON-en.json in Resources */, - 2BD85320208130A100FB0E53 /* Storyboard.storyboard in Resources */, - 9F761AEC1E3063E400904B4B /* lang-en.json in Resources */, - 9F4570221E3173A4008C37D1 /* lang-es.json in Resources */, - 9F1677FA1E51DE270022F3F8 /* Strings.strings in Resources */, - 2BD853272081316E00FB0E53 /* langTable-en.json in Resources */, - 9FA3BC4D1E318BDC0054CA92 /* some-it.json in Resources */, - 9FA3BC4B1E318BCB0054CA92 /* other-en.json in Resources */, - 9FCD8EA01E52A9D800B5909C /* Other.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -315,6 +311,18 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2B931AAF2083031000C26D6B /* badJSON-en.json in Resources */, + 2B931AB22083031700C26D6B /* Storyboard.storyboard in Resources */, + 2B931AAD2083031000C26D6B /* some-it.json in Resources */, + 2B931AB02083031700C26D6B /* Strings.strings in Resources */, + 2B931AAE2083031000C26D6B /* file-de.json in Resources */, + 2B931AAC2083031000C26D6B /* other-es.json in Resources */, + 2B931AB12083031700C26D6B /* Other.strings in Resources */, + 2B931AA8208302FB00C26D6B /* lang-en.json in Resources */, + 2B931AA92083030400C26D6B /* langTable-en.json in Resources */, + 2B931AAA2083030700C26D6B /* lang-es.json in Resources */, + 2B931AAB2083031000C26D6B /* other-en.json in Resources */, + 2BB606BA2083120F00DFEF11 /* lang-fr.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -372,6 +380,7 @@ isa = PBXVariantGroup; children = ( 2BD85325208130B400FB0E53 /* Base */, + 2B80F11B20830FBD00542924 /* fr */, ); name = Storyboard.storyboard; sourceTree = ""; @@ -381,6 +390,7 @@ children = ( 9F1677FB1E51DE270022F3F8 /* en */, 9F1677FD1E51DE320022F3F8 /* es */, + 2B80F11C20830FBD00542924 /* fr */, ); name = Strings.strings; sourceTree = ""; @@ -390,6 +400,7 @@ children = ( 9FCD8EA11E52A9D800B5909C /* en */, 9FCD8EA31E52A9D900B5909C /* es */, + 2B80F11D20830FBD00542924 /* fr */, ); name = Other.strings; sourceTree = ""; diff --git a/Localize.xcodeproj/xcshareddata/xcschemes/Localize.xcscheme b/Localize.xcodeproj/xcshareddata/xcschemes/Localize.xcscheme index 5f93056..e17b8b1 100644 --- a/Localize.xcodeproj/xcshareddata/xcschemes/Localize.xcscheme +++ b/Localize.xcodeproj/xcshareddata/xcschemes/Localize.xcscheme @@ -40,6 +40,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "en" codeCoverageEnabled = "YES" shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/README.md b/README.md index d60d295..f8e8bb7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # Localize [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +[![codecov.io](https://codecov.io/github/andresilvagomez/Localize/coverage.svg?branch=master)](https://codecov.io/github/andresilvagomez/Localize?branch=master) [![CocoaPods](https://img.shields.io/cocoapods/v/Localize.svg)](https://cocoapods.org/pods/Localize) [![Build Status](https://travis-ci.org/andresilvagomez/Localize.svg?branch=master)](https://travis-ci.org/andresilvagomez/Localize) [![Language](https://img.shields.io/badge/language-Swift%204.1-orange.svg)](https://swift.org) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Kekiiwaa/Localize/master/LICENSE) +[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/vsouza/awesome-ios) Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings. @@ -47,11 +49,11 @@ To integrate Localize into your Xcode project using CocoaPods, specify it in you ```ruby source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '8.0' +platform :ios, '9.0' use_frameworks! target '' do - pod 'Localize' , '~> 2.0.0' + pod 'Localize' , '~> 2.0.1' end ``` diff --git a/Source/Localize.swift b/Source/Localize.swift index 934e092..2b82463 100644 --- a/Source/Localize.swift +++ b/Source/Localize.swift @@ -125,12 +125,6 @@ public class Localize: NSObject { return provider.displayNameForLanguage(language) } - /// Enable testing mode - /// Please not use in your code, is only for test schema. - public func enableTestingMode() { - provider.enableTestingMode() - } - // MARK: Config providers /// Update provider to localize your app. diff --git a/Source/LocalizeCommonProtocol.swift b/Source/LocalizeCommonProtocol.swift index 6041db0..e8edaaf 100644 --- a/Source/LocalizeCommonProtocol.swift +++ b/Source/LocalizeCommonProtocol.swift @@ -7,7 +7,14 @@ import UIKit -class LocalizeCommonProtocol: NSObject { +class LocalizeCommonProtocol: LocalizeProtocol { + + /// Show all aviable languajes whit criteria name + /// + /// - returns: list with storaged languages code + var availableLanguages: [String] { + return ["en"] + } /// Name for storaged Json Files /// The rule for name is fileName-LanguageKey.json @@ -16,9 +23,6 @@ class LocalizeCommonProtocol: NSObject { /// Bundle used to load files from. /// Defaults to the main bundle. private var usedBundle = Bundle.main - - /// Use this for testing mode, search resources in different bundles. - public var testing: Bool = false /// Default language, if this can't find a key in your current language /// Try read key in default language @@ -31,7 +35,7 @@ class LocalizeCommonProtocol: NSObject { if let lang = defaults.string(forKey: LocalizeStorageKey) { return lang } - return Locale.preferredLanguages[0] + return Locale.preferredLanguages.first ?? defaultLanguage } } @@ -41,9 +45,6 @@ class LocalizeCommonProtocol: NSObject { /// /// - returns: a string url where is your file internal var bundle: Bundle { - if testing { - return Bundle(for: type(of: self)) - } return usedBundle } @@ -84,12 +85,6 @@ class LocalizeCommonProtocol: NSObject { return "" } - /// Enable testing mode - /// Please not use in your code, is only for test schema. - public func enableTestingMode() { - testing = true - } - /// Update base file name, searched in path. public func update(fileName: String) { self.fileName = fileName @@ -119,7 +114,7 @@ class LocalizeCommonProtocol: NSObject { /// /// - returns: localized key or same text public func localize(key: String, replace: String, tableName: String? = nil) -> String { - let string = localize(key: key, tableName:tableName) + let string = localize(key: key, tableName: tableName) return string.replacingOccurrences(of: "%", with: replace) } @@ -131,7 +126,7 @@ class LocalizeCommonProtocol: NSObject { /// /// - returns: localized key or same text public func localize(key: String, values replace: [Any], tableName: String? = nil) -> String { - var string = localize(key: key, tableName:tableName) + var string = localize(key: key, tableName: tableName) if string == key { return key } diff --git a/Source/LocalizeJson.swift b/Source/LocalizeJson.swift index 33197d1..21aaaad 100644 --- a/Source/LocalizeJson.swift +++ b/Source/LocalizeJson.swift @@ -60,7 +60,7 @@ fileprivate extension JSON { } } -class LocalizeJson: LocalizeCommonProtocol, LocalizeProtocol { +class LocalizeJson: LocalizeCommonProtocol { /// Create default lang name override init() { @@ -71,7 +71,7 @@ class LocalizeJson: LocalizeCommonProtocol, LocalizeProtocol { /// Show all aviable languages with criteria name /// /// - returns: list with storaged languages code - public var availableLanguages: [String] { + override var availableLanguages: [String] { var languages : [String] = [] for localeId in NSLocale.availableLocaleIdentifiers { diff --git a/Source/LocalizeProtocol.swift b/Source/LocalizeProtocol.swift index 059f5cd..4237369 100644 --- a/Source/LocalizeProtocol.swift +++ b/Source/LocalizeProtocol.swift @@ -9,9 +9,6 @@ import UIKit protocol LocalizeProtocol { - /// Use this for testing mode, search resources in different bundles. - var testing: Bool {get set} - /// Default language, if this can't find a key in your current language /// Try read key in default language var defaultLanguage: String {get set} @@ -85,8 +82,4 @@ protocol LocalizeProtocol { /// - return: String form language code in current user language func displayNameForLanguage(_ language: String) -> String - /// Enable testing mode - /// Please not use in your code, is only for test schema. - func enableTestingMode() - } diff --git a/Source/LocalizeStatic.swift b/Source/LocalizeStatic.swift index cf0ca5a..858a889 100644 --- a/Source/LocalizeStatic.swift +++ b/Source/LocalizeStatic.swift @@ -95,12 +95,6 @@ extension Localize { return Localize.shared.displayNameForLanguage(language) } - /// Enable testing mode - /// Please not use in your code, is only for test schema. - public static func enableTestingMode() { - Localize.shared.enableTestingMode() - } - // MARK: Config providers /// Update provider to localize your app. diff --git a/Source/LocalizeStrings.swift b/Source/LocalizeStrings.swift index ade26e8..5ac00de 100644 --- a/Source/LocalizeStrings.swift +++ b/Source/LocalizeStrings.swift @@ -7,7 +7,7 @@ import UIKit -class LocalizeStrings: LocalizeCommonProtocol, LocalizeProtocol { +class LocalizeStrings: LocalizeCommonProtocol { /// Create default lang name override init() { @@ -18,7 +18,7 @@ class LocalizeStrings: LocalizeCommonProtocol, LocalizeProtocol { /// Show all aviable languajes whit criteria name /// /// - returns: list with storaged languages code - public var availableLanguages: [String] { + override var availableLanguages: [String] { var availableLanguages = bundle.localizations if let indexOfBase = availableLanguages.index(of: "Base") { availableLanguages.remove(at: indexOfBase) diff --git a/Tests/BaseTest.swift b/Tests/BaseTest.swift index e226547..02bd623 100644 --- a/Tests/BaseTest.swift +++ b/Tests/BaseTest.swift @@ -13,10 +13,20 @@ class BaseTest: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") } + func testRemoveKeyAndGetDefaultForLang() { + UserDefaults.standard.removeObject(forKey: LocalizeStorageKey) + XCTAssertTrue(Localize.currentLanguage == Locale.preferredLanguages.first) + } + + func testSameKeyWithTableName() { + let localized = "heymamiwhereareyou".localize(values: "", "", tableName: "heymamiwhereareyou") + XCTAssertTrue(localized == "heymamiwhereareyou") + } + func testLocalizeInAnyDictionary() { let localized = "heymomhowareyoy".localized XCTAssertTrue(localized == "heymomhowareyoy") @@ -64,7 +74,7 @@ class BaseTest: XCTestCase { func testListOfAvailableLanguages() { let languages = Localize.availableLanguages - XCTAssertTrue(languages == ["en", "es"]) + XCTAssertTrue(languages.count == 3) } func testCurrentLanguage() { diff --git a/Tests/BaseTestInSpanish.swift b/Tests/BaseTestInSpanish.swift index a87e265..34a0456 100644 --- a/Tests/BaseTestInSpanish.swift +++ b/Tests/BaseTestInSpanish.swift @@ -13,10 +13,15 @@ class BaseTestInSpanish: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "es") } + func testRemoveKeyAndGetDefaultForLang() { + UserDefaults.standard.removeObject(forKey: LocalizeStorageKey) + XCTAssertTrue(Localize.currentLanguage == Locale.preferredLanguages.first) + } + func testLocalizeKey() { let localized = "hello.world".localize() XCTAssertTrue(localized == "Hola mundo!") @@ -54,7 +59,8 @@ class BaseTestInSpanish: XCTestCase { func testListOfAvailableLanguages() { let languages = Localize.availableLanguages - XCTAssertTrue(languages == ["en", "es"]) + // ["en", "es", "fr"] + XCTAssertTrue(languages.count == 3) } func testCurrentLanguage() { diff --git a/Tests/JSONBadSources.swift b/Tests/JSONBadSources.swift index 5ea2d7f..e2cdc27 100644 --- a/Tests/JSONBadSources.swift +++ b/Tests/JSONBadSources.swift @@ -13,7 +13,7 @@ class JSONBadSources: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") Localize.update(defaultLanguage: "rs") } diff --git a/Tests/JsonChanginFileName.swift b/Tests/JsonChanginFileName.swift index fd12eb1..b18d570 100644 --- a/Tests/JsonChanginFileName.swift +++ b/Tests/JsonChanginFileName.swift @@ -15,7 +15,7 @@ class JsonChanginFileName: XCTestCase { Localize.update(provider: .json) Localize.update(language: "es") Localize.update(fileName: "lang") - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) } func testKeyInOtherLanguage() { diff --git a/Tests/OtherLangTest.swift b/Tests/OtherLangTest.swift index 6fc0150..371e4eb 100644 --- a/Tests/OtherLangTest.swift +++ b/Tests/OtherLangTest.swift @@ -13,7 +13,7 @@ class OtherLangTest: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "it") } diff --git a/Tests/ReadingOtherFiles.swift b/Tests/ReadingOtherFiles.swift index 521507c..ba2dccd 100644 --- a/Tests/ReadingOtherFiles.swift +++ b/Tests/ReadingOtherFiles.swift @@ -16,7 +16,7 @@ class ReadingOtherFiles: XCTestCase { } func testOtherEnglish() { - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") Localize.update(fileName: "other") let result = "hello".localize() @@ -24,7 +24,7 @@ class ReadingOtherFiles: XCTestCase { } func testSomeItalian() { - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "it") Localize.update(fileName: "some") let result = "hello".localize() @@ -32,7 +32,7 @@ class ReadingOtherFiles: XCTestCase { } func testFileGerman() { - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "de") Localize.update(fileName: "file") let result = "hello".localize() diff --git a/Tests/StringBadSources.swift b/Tests/StringBadSources.swift index cbae8a6..3794630 100644 --- a/Tests/StringBadSources.swift +++ b/Tests/StringBadSources.swift @@ -13,7 +13,7 @@ class StringBadSources: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .strings) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") Localize.update(defaultLanguage: "rs") } diff --git a/Tests/StringBaseTest.swift b/Tests/StringBaseTest.swift index 9152e80..02e9d3c 100644 --- a/Tests/StringBaseTest.swift +++ b/Tests/StringBaseTest.swift @@ -13,7 +13,7 @@ class StringBaseTest: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .strings) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") } @@ -54,7 +54,7 @@ class StringBaseTest: XCTestCase { func testListOfAvailableLanguages() { let languages = Localize.availableLanguages - XCTAssertTrue(languages == ["en", "es"]) + XCTAssertTrue(languages == ["en", "es", "fr"]) } func testCurrentLanguage() { diff --git a/Tests/StringBaseTestInSpanish.swift b/Tests/StringBaseTestInSpanish.swift index b1231ce..20ad773 100644 --- a/Tests/StringBaseTestInSpanish.swift +++ b/Tests/StringBaseTestInSpanish.swift @@ -13,7 +13,7 @@ class StringBaseTestInSpanish: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .strings) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "es") } @@ -54,7 +54,7 @@ class StringBaseTestInSpanish: XCTestCase { func testListOfAvailableLanguages() { let languages = Localize.availableLanguages - XCTAssertTrue(languages == ["en", "es"]) + XCTAssertTrue(languages == ["en", "es", "fr"]) } func testCurrentLanguage() { diff --git a/Tests/StringsChanginDefaultFileName.swift b/Tests/StringsChanginDefaultFileName.swift index 629a940..b206e1e 100644 --- a/Tests/StringsChanginDefaultFileName.swift +++ b/Tests/StringsChanginDefaultFileName.swift @@ -15,7 +15,7 @@ class StringsChanginDefaultFileName: XCTestCase { Localize.update(provider: .strings) Localize.update(language: "en") Localize.update(fileName: "Other") - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) } func testKeyInOtherLanguage() { diff --git a/Tests/UIViewComponents.swift b/Tests/UIViewComponents.swift index 09ee68c..477b74a 100644 --- a/Tests/UIViewComponents.swift +++ b/Tests/UIViewComponents.swift @@ -15,7 +15,7 @@ class UIViewComponents: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") } diff --git a/Tests/UIViewComponentsES.swift b/Tests/UIViewComponentsES.swift index 30cd144..4a7186d 100644 --- a/Tests/UIViewComponentsES.swift +++ b/Tests/UIViewComponentsES.swift @@ -15,7 +15,7 @@ class UIViewComponentsES: XCTestCase { override func setUp() { super.setUp() Localize.update(provider: .json) - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "es") } diff --git a/Tests/UIViewComponentsWithString.swift b/Tests/UIViewComponentsWithString.swift index a9efc38..a80f807 100644 --- a/Tests/UIViewComponentsWithString.swift +++ b/Tests/UIViewComponentsWithString.swift @@ -13,7 +13,7 @@ import Localize class UIViewComponentsWithString: XCTestCase { override func setUp() { super.setUp() - Localize.enableTestingMode() + Localize.update(bundle: Bundle(for: type(of: self))) Localize.update(language: "en") } diff --git a/Tests/fr.lproj/Storyboard.storyboard b/Tests/fr.lproj/Storyboard.storyboard deleted file mode 100644 index f9a048e..0000000 --- a/Tests/fr.lproj/Storyboard.storyboard +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Tests/fr.lproj/Storyboard.strings b/Tests/fr.lproj/Storyboard.strings new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Tests/fr.lproj/Storyboard.strings @@ -0,0 +1 @@ + diff --git a/Tests/lang-fr.json b/Tests/lang-fr.json new file mode 100644 index 0000000..f4d69c9 --- /dev/null +++ b/Tests/lang-fr.json @@ -0,0 +1,25 @@ +{ + "name" : "Hello %", + "hello" : { + "world" : "Hello world!" + }, + "values" : "Hello everyone my name is % and I'm %, see you soon", + "username" : "My username is :username", + "level" : { + "one" : { + "two" : { + "three" : "This is a multilevel key" + } + } + }, + "the.same.lavel" : "This is a localized in the same level", + "enlish" : "This key only exist in english file.", + "segment": { + "base": { + "one": "First", + "two": "Second" + } + }, + "one": "First", + "two": "Second" +}