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

Feature/filter generated translation #268

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions R.swift/ResourceTypes/LocalizableStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ struct LocalizableStrings : WhiteListedExtensionsResourceType {
self.locale = locale
self.dictionary = dictionary
}

func isLocalizedNibOrStoryboard(names: Set<String>) -> Bool {
if locale == .None {
return false
}

return names.contains(filename)
}
}

private func parseStrings(nsDictionary: NSDictionary, source: String) throws -> [String : (params: [StringParam], commentValue: String)] {
Expand Down
8 changes: 7 additions & 1 deletion R.swift/ResourceTypes/Resources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ struct Resources {
resourceFiles = resourceURLs.flatMap { url in tryResourceParsing { try ResourceFile(url: url) } }
reusables = (nibs.map { $0 as ReusableContainer } + storyboards.map { $0 as ReusableContainer })
.flatMap { $0.reusables }
localizableStrings = resourceURLs.flatMap { url in tryResourceParsing { try LocalizableStrings(url: url) } }


let nibAndStoryboardNames = Set(nibs.map { $0.name } + storyboards.map { $0.name })

localizableStrings = resourceURLs
.flatMap { url in tryResourceParsing { try LocalizableStrings(url: url) } }
.filter { !$0.isLocalizedNibOrStoryboard(nibAndStoryboardNames) }
}
}

Expand Down
38 changes: 38 additions & 0 deletions ResourceApp/ResourceApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
DEF559AE1CA48892009B8C51 /* ResourceAppTests_tvOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF559AD1CA48892009B8C51 /* ResourceAppTests_tvOS.swift */; };
DEF559B71CA48DC2009B8C51 /* R.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF559B61CA48DC2009B8C51 /* R.generated.swift */; };
DEF559B91CA4932F009B8C51 /* Rswift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEF559B81CA4932F009B8C51 /* Rswift.framework */; };
E209EC451D6D681700308357 /* LocalizedStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E209EC471D6D681700308357 /* LocalizedStoryboard.storyboard */; };
E209EC4C1D6D68B800308357 /* LocalizedNib.xib in Resources */ = {isa = PBXBuildFile; fileRef = E209EC4E1D6D68B800308357 /* LocalizedNib.xib */; };
E2156B631CC4042900F341DC /* Settings.strings in Resources */ = {isa = PBXBuildFile; fileRef = E2156B651CC4042900F341DC /* Settings.strings */; };
E2156B681CC41EB400F341DC /* Generic.strings in Resources */ = {isa = PBXBuildFile; fileRef = E2156B671CC41EB400F341DC /* Generic.strings */; };
E2156B6A1CC4292600F341DC /* Duplicate.strings in Resources */ = {isa = PBXBuildFile; fileRef = E2156B691CC4292600F341DC /* Duplicate.strings */; };
Expand Down Expand Up @@ -173,6 +175,11 @@
DEF559AF1CA48892009B8C51 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DEF559B61CA48DC2009B8C51 /* R.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = R.generated.swift; sourceTree = "<group>"; };
DEF559B81CA4932F009B8C51 /* Rswift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Rswift.framework; path = "../R.swift.Library/build/Debug-appletvos/Rswift.framework"; sourceTree = "<group>"; };
E209EC461D6D681700308357 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LocalizedStoryboard.storyboard; sourceTree = "<group>"; };
E209EC491D6D681B00308357 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LocalizedStoryboard.strings; sourceTree = "<group>"; };
E209EC4D1D6D68B800308357 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LocalizedNib.xib; sourceTree = "<group>"; };
E209EC521D6D707E00308357 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/LocalizedNib.strings; sourceTree = "<group>"; };
E209EC531D6D71F300308357 /* nl */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nl; path = nl.lproj/LocalizedNib.xib; sourceTree = "<group>"; };
E2156B641CC4042900F341DC /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Settings.strings; sourceTree = "<group>"; };
E2156B661CC4043C00F341DC /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Settings.strings; sourceTree = "<group>"; };
E2156B671CC41EB400F341DC /* Generic.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Generic.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -310,6 +317,7 @@
D55C6CBA1B5D757300301B0D /* ResourceApp */ = {
isa = PBXGroup;
children = (
E209EC421D6D67B600308357 /* Localized */,
E2F268AF1C92BFE00093995D /* Colors */,
D55C6CC61B5D757300301B0D /* Images.xcassets */,
D51E60BF1BB13612004BB376 /* Images */,
Expand Down Expand Up @@ -432,6 +440,15 @@
path = "ResourceAppTests-tvOS";
sourceTree = "<group>";
};
E209EC421D6D67B600308357 /* Localized */ = {
isa = PBXGroup;
children = (
E209EC471D6D681700308357 /* LocalizedStoryboard.storyboard */,
E209EC4E1D6D68B800308357 /* LocalizedNib.xib */,
);
path = Localized;
sourceTree = "<group>";
};
E2A10EF61CD13768006BFC63 /* Relative To Project */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -621,6 +638,7 @@
D55C6CCA1B5D757300301B0D /* LaunchScreen.xib in Resources */,
C378DD7A1C68C2BF003598B8 /* SupplementaryElement.xib in Resources */,
E2762AC01CCCDFDA0009BCAA /* Settings.stringsdict in Resources */,
E209EC451D6D681700308357 /* LocalizedStoryboard.storyboard in Resources */,
D5AD5C991B7A7CE700A8B96C /* Duplicate.storyboard in Resources */,
D5BA2E5F1C90086C0025C9E3 /* CellCollectionView.xib in Resources */,
D5AD5CA11B7A926200A8B96C /* DuplicateCellView.xib in Resources */,
Expand All @@ -634,6 +652,7 @@
D55C6CC71B5D757300301B0D /* Images.xcassets in Resources */,
D52725FC1C4A7C6A0005C8D4 /* Sky.tiff in Resources */,
D5E513BE1B8E111A0035ECAA /* GdyBkltter1911.ttf in Resources */,
E209EC4C1D6D68B800308357 /* LocalizedNib.xib in Resources */,
D51E60C61BB1E600004BB376 /* User@[email protected] in Resources */,
E2156B6E1CC42B6700F341DC /* @@.strings in Resources */,
D51E60C11BB13626004BB376 /* Colors.jpg in Resources */,
Expand Down Expand Up @@ -894,6 +913,25 @@
name = Main.storyboard;
sourceTree = "<group>";
};
E209EC471D6D681700308357 /* LocalizedStoryboard.storyboard */ = {
isa = PBXVariantGroup;
children = (
E209EC461D6D681700308357 /* Base */,
E209EC491D6D681B00308357 /* nl */,
);
name = LocalizedStoryboard.storyboard;
sourceTree = "<group>";
};
E209EC4E1D6D68B800308357 /* LocalizedNib.xib */ = {
isa = PBXVariantGroup;
children = (
E209EC4D1D6D68B800308357 /* Base */,
E209EC521D6D707E00308357 /* es */,
E209EC531D6D71F300308357 /* nl */,
);
name = LocalizedNib.xib;
sourceTree = "<group>";
};
E2156B651CC4042900F341DC /* Settings.strings */ = {
isa = PBXVariantGroup;
children = (
Expand Down
25 changes: 25 additions & 0 deletions ResourceApp/ResourceApp/Localized/Base.lproj/LocalizedNib.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Hello, world" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QsP-tg-2S7">
<frame key="frameInset" minX="8" minY="8" width="91" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="xJg-Pw-cJp">
<objects>
<viewController id="wtH-YI-alN" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="NQx-Kc-fZi"/>
<viewControllerLayoutGuide type="bottom" id="MdS-14-JjF"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="RYg-h9-h1M">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Hello, world!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xcR-Ea-4D3">
<frame key="frameInset" minX="16" minY="20" width="95" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bYY-Rh-Ke1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-964" y="-1115"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

/* Class = "UILabel"; text = "Hello, world"; ObjectID = "QsP-tg-2S7"; */
"QsP-tg-2S7.text" = "Hola, Mundo";
25 changes: 25 additions & 0 deletions ResourceApp/ResourceApp/Localized/nl.lproj/LocalizedNib.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Hello, world" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QsP-tg-2S7">
<frame key="frameInset" minX="8" minY="8" width="91" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="0.25897606382978722" colorSpace="calibratedRGB"/>
</view>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

/* Class = "UILabel"; text = "Hello, world!"; ObjectID = "xcR-Ea-4D3"; */
"xcR-Ea-4D3.text" = "Hallo, wereld!";