Skip to content

Commit

Permalink
Merge branch 'release/3.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Jun 7, 2018
2 parents 95a54dc + f625dac commit 1f6be93
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 102 deletions.
4 changes: 2 additions & 2 deletions CoconutKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 3.3.3;
MARKETING_VERSION = 3.3.4;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -3601,7 +3601,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 3.3.3;
MARKETING_VERSION = 3.3.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Demo/InnerBundle/InnerBundle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
6F44EA12156BB2AF00B45BB4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
Expand Down Expand Up @@ -190,6 +191,7 @@
6F44EA13156BB2AF00B45BB4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="6245" systemVersion="13F34" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" colorMatched="YES">
<device id="ipad9_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DynamicLocalizationDemoViewController">
Expand All @@ -17,17 +22,24 @@
<rect key="frame" x="0.0" y="0.0" width="768" height="1004"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="LS/String in Localizable.strings" lineBreakMode="tailTruncation" minimumFontSize="10" id="29">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" usesAttributedText="YES" lineBreakMode="tailTruncation" minimumFontSize="10" id="29">
<rect key="frame" x="22" y="89" width="572" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<attributedString key="attributedText">
<fragment content="LS/String in Localizable.strings">
<attributes>
<color key="NSColor" red="0.016804177310000001" green="0.19835099580000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="17" name="Courier"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="truncatingTail" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="ULS/Uppercase string in Localizable.strings" lineBreakMode="tailTruncation" minimumFontSize="10" id="30">
<rect key="frame" x="22" y="118" width="572" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.75974334759999995" green="0.7767839312" blue="0.94437579719999998" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.75974334759999995" green="0.7767839312" blue="0.94437579719999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -138,7 +150,7 @@
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="LS/Missing localization table in main bundle" lineBreakMode="tailTruncation" minimumFontSize="10" id="52">
<rect key="frame" x="22" y="466" width="572" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.75974334759999995" green="0.7767839312" blue="0.94437579719999998" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.75974334759999995" green="0.7767839312" blue="0.94437579719999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -171,15 +183,15 @@
<rect key="frame" x="233" y="697" width="302" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<state key="normal" title="LS/Button label, default">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" title="LS/Button label, highlighted"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="67">
<rect key="frame" x="233" y="742" width="302" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<state key="normal" title="LS/Click for missing translation">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" title="LS/Missing translation"/>
</button>
Expand All @@ -196,7 +208,7 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.83921568629999999" green="0.83921568629999999" blue="0.83921568629999999" alpha="1" colorSpace="deviceRGB"/>
<color key="backgroundColor" red="0.80214887857437134" green="0.80212485790252686" blue="0.80213844776153564" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="locTable" value="InnerTable"/>
<userDefinedRuntimeAttribute type="string" keyPath="locBundle" value="InnerBundle"/>
Expand Down Expand Up @@ -224,21 +236,16 @@
<rect key="frame" x="602" y="458" width="145" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<state key="normal" title="LS/Change color">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="changeColor:" destination="-1" eventType="touchUpInside" id="73"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ + (void)load
HLSSwizzleSelector(self, @selector(initWithFrame:), swizzle_initWithFrame, &s_initWithFrame);
HLSSwizzleSelector(self, @selector(initWithCoder:), swizzle_initWithCoder, &s_initWithCoder);
HLSSwizzleSelector(self, @selector(setSelectedSegmentIndex:), swizzle_setSelectedSegmentIndex, &s_setSelectedSegmentIndex);

}

#pragma mark HLSViewBindingImplementation protocol implementation
Expand Down
13 changes: 12 additions & 1 deletion Framework/Sources/View/HLSLabelLocalizationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,29 @@ typedef NS_ENUM(NSInteger, HLSLabelRepresentation) {
* default localization table name). The main bundle is used if bundleName is set to nil. Bundles are searched
* recursively in the main bundle
*/
- (instancetype)initWithAttributedText:(nullable NSAttributedString *)attributedText tableName:(nullable NSString *)tableName bundleName:(nullable NSString *)bundleName NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithAttributedText:(nullable NSAttributedString *)attributedText text:(nullable NSString *)text tableName:(nullable NSString *)tableName bundleName:(nullable NSString *)bundleName NS_DESIGNATED_INITIALIZER;

/**
* Return YES iff the information object corresponds to localized content
*/
@property (nonatomic, readonly, getter=isLocalized) BOOL localized;

/**
* Return YES iff the underlying string is attributed.
*/
@property (nonatomic, readonly, getter=isAttributed) BOOL attributed;

/**
* Return YES iff some localization information is missing (localized key, corresponding translation, etc.)
*/
@property (nonatomic, readonly, getter=isIncomplete) BOOL incomplete;

/**
* Build and return the corresponding localized text. Return nil if the object does not contain localized information
* (i.e. if isLocalized returns NO)
*/
@property (nonatomic, readonly, copy, nullable) NSString *localizedText;

/**
* Build and return the corresponding localized attributed text. Return nil if the object does not contain localized information
* (i.e. if isLocalized returns NO)
Expand Down
69 changes: 40 additions & 29 deletions Framework/Sources/View/HLSLabelLocalizationInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@interface HLSLabelLocalizationInfo ()

@property (nonatomic, copy) NSAttributedString *originalAttributedText;
@property (nonatomic, copy) NSString *originalText;

@property (nonatomic, copy) NSString *localizationKey;
@property (nonatomic, copy) NSString *tableName;
@property (nonatomic, copy) NSString *bundleName;
Expand All @@ -28,12 +30,14 @@ @implementation HLSLabelLocalizationInfo

#pragma mark Object creation and destruction

- (instancetype)initWithAttributedText:(NSAttributedString *)attributedText tableName:(NSString *)tableName bundleName:(NSString *)bundleName
- (instancetype)initWithAttributedText:(NSAttributedString *)attributedText text:(NSString *)text tableName:(NSString *)tableName bundleName:(NSString *)bundleName
{
if (self = [super init]) {
[self parseAttributedText:attributedText];
[self parseText:attributedText.string ?: text];

self.originalAttributedText = attributedText;
self.originalText = text;

self.tableName = tableName;
self.bundleName = bundleName;
}
Expand All @@ -48,15 +52,13 @@ - (instancetype)init

#pragma mark Parsing text

- (void)parseAttributedText:(NSAttributedString *)attributedText
- (void)parseText:(NSString *)text
{
static NSString * const kNormalLeadingPrefix = @"LS/";
static NSString * const kUppercaseLeadingPrefix = @"ULS/";
static NSString * const kLowercaseLeadingPrefix = @"LLS/";
static NSString * const kCapitalizedLeadingPrefix = @"CLS/";

NSString *text = attributedText.string;

// Check prefix
NSString *prefix = nil;
if ([text hasPrefix:kNormalLeadingPrefix]) {
Expand Down Expand Up @@ -91,6 +93,11 @@ - (BOOL)isLocalized
return self.localizationKey != nil;
}

- (BOOL)isAttributed
{
return self.originalAttributedText != nil;
}

- (BOOL)isIncomplete
{
// Missing localization key
Expand All @@ -116,29 +123,35 @@ - (BOOL)isIncomplete
}

- (NSAttributedString *)localizedAttributedText
{
{
NSString *text = [self localizedText];
NSMutableAttributedString *attributedText = [self.originalAttributedText mutableCopy];
[attributedText replaceCharactersInRange:NSMakeRange(0, attributedText.length) withString:text];
return [attributedText copy];
}

- (NSString *)localizedText
{
if (! self.localizationKey) {
return nil;
}

NSString *text = nil;

// Missing localization key. Return some label to make it clear when the label is displayed on screen
if (self.localizationKey.length == 0) {
text = @"(no key)";
return @"(no key)";
}
else {
// We use an explicit constant string for missing localizations since otherwise the localization key itself would
// be returned by the localizedStringForKey:value:table method
NSBundle *bundle = [NSBundle bundleWithName:self.bundleName];
if (! bundle) {
HLSLoggerWarn(@"The bundle %@ was not found", self.bundleName);
text = self.localizationKey;
return self.localizationKey;
}
else {
text = [bundle localizedStringForKey:self.localizationKey
value:kMissingLocalizedString
table:self.tableName];
NSString *text = [bundle localizedStringForKey:self.localizationKey
value:kMissingLocalizedString
table:self.tableName];

// Use the localization key as text if missing
if ([text isEqualToString:kMissingLocalizedString]) {
Expand All @@ -147,31 +160,29 @@ - (NSAttributedString *)localizedAttributedText

// Formatting
switch (self.representation) {
case HLSLabelRepresentationUppercase: {
text = text.localizedUppercaseString;
break;
}
case HLSLabelRepresentationUppercase: {
text = text.localizedUppercaseString;
break;
}

case HLSLabelRepresentationLowercase: {
text = text.localizedLowercaseString;
break;
}
case HLSLabelRepresentationLowercase: {
text = text.localizedLowercaseString;
break;
}

case HLSLabelRepresentationCapitalized: {
text = text.localizedCapitalizedString;
break;
}
case HLSLabelRepresentationCapitalized: {
text = text.localizedCapitalizedString;
break;
}

default: {
break;
}
}

return text;
}
}

NSMutableAttributedString *attributedText = [self.originalAttributedText mutableCopy];
[attributedText replaceCharactersInRange:NSMakeRange(0, attributedText.length) withString:text];
return [attributedText copy];
}

#pragma mark Description
Expand Down
3 changes: 3 additions & 0 deletions Framework/Sources/View/UILabel+HLSDynamicLocalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ NS_ASSUME_NONNULL_BEGIN
* - LLS/<localizationKey>: Same as LS/, but lowercase
* - CLS/<localizationKey>: Same as LS/, but capitalized
*
* Dynamic localization works both with usual text as well as with attributed text. When attributed text is localized
* this way, though, only global formatting is preserved though, special formatting applied on subranges is lost.
*
* Lookup is performed in the Localizable.strings file of the main bundle. If you need lookup to be performed
* in another table, respectively another bundle, set the following user-defined runtime attributes on the
* label or button you want to localize:
Expand Down

0 comments on commit 1f6be93

Please sign in to comment.