mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Merge pull request #126 from ryohey/fix-localized-files
Fix localized files with same name
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
Project
|
||||
|
||||
Created by ryohey on 2017/11/03.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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>StringKey</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
<string>%#@VARIABLE@</string>
|
||||
<key>Variable</key>
|
||||
<dict>
|
||||
<key>NSStringFormatSpecTypeKey</key>
|
||||
<string>NSStringPluralRuleType</string>
|
||||
<key>NSStringFormatValueTypeKey</key>
|
||||
<string></string>
|
||||
<key>zero</key>
|
||||
<string></string>
|
||||
<key>one</key>
|
||||
<string></string>
|
||||
<key>two</key>
|
||||
<string></string>
|
||||
<key>few</key>
|
||||
<string></string>
|
||||
<key>many</key>
|
||||
<string></string>
|
||||
<key>other</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
Project
|
||||
|
||||
Created by ryohey on 2017/11/03.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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>StringKey</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
<string>%#@VARIABLE@</string>
|
||||
<key>Variable</key>
|
||||
<dict>
|
||||
<key>NSStringFormatSpecTypeKey</key>
|
||||
<string>NSStringPluralRuleType</string>
|
||||
<key>NSStringFormatValueTypeKey</key>
|
||||
<string></string>
|
||||
<key>zero</key>
|
||||
<string></string>
|
||||
<key>one</key>
|
||||
<string></string>
|
||||
<key>two</key>
|
||||
<string></string>
|
||||
<key>few</key>
|
||||
<string></string>
|
||||
<key>many</key>
|
||||
<string></string>
|
||||
<key>other</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -18,10 +18,12 @@
|
||||
BF3008399601 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR3032072503 /* Alamofire.framework */; };
|
||||
BF3154421201 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FR5980633301 /* Assets.xcassets */; settings = {COMPILER_FLAGS = "-Werror"; }; };
|
||||
BF3314441201 = {isa = PBXBuildFile; fileRef = FR5251191201 /* Framework_macOS.framework */; };
|
||||
BF3371332801 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = VG5506161801 /* Localizable.strings */; };
|
||||
BF3515549501 /* MyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = FR7740960501 /* MyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
BF3515549502 /* MyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = FR7740960501 /* MyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
BF3515549503 /* MyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = FR7740960501 /* MyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
BF3515549504 /* MyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = FR7740960501 /* MyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
BF4414242001 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = VG1597538701 /* Localizable.stringsdict */; };
|
||||
BF4530793601 /* Framework_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR4722960401 /* Framework_iOS.framework */; };
|
||||
BF5539436901 = {isa = PBXBuildFile; fileRef = FR6623158301 /* Framework_tvOS.framework */; };
|
||||
BF6380159901 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR3032072502 /* Alamofire.framework */; };
|
||||
@@ -77,6 +79,8 @@
|
||||
FR3032072503 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Alamofire.framework; sourceTree = "<group>"; };
|
||||
FR3032072504 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Alamofire.framework; sourceTree = "<group>"; };
|
||||
FR3546283901 /* base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = base.xcconfig; sourceTree = "<group>"; };
|
||||
FR3899172901 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
FR3899172902 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
FR4387045301 /* Framework_watchOS.framework */ = {isa = PBXFileReference; explicitFileType = framework; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Framework_watchOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FR4722960401 /* Framework_iOS.framework */ = {isa = PBXFileReference; explicitFileType = framework; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Framework_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FR4822987701 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LocalizedStoryboard.storyboard; sourceTree = "<group>"; };
|
||||
@@ -92,6 +96,8 @@
|
||||
FR7831228901 /* App_iOS_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = xctest; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = App_iOS_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FR8182352201 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LocalizedStoryboard.strings; sourceTree = "<group>"; };
|
||||
FR8252321101 /* App_iOS.app */ = {isa = PBXFileReference; explicitFileType = app; includeInIndex = 0; lastKnownFileType = wrapper.application; path = App_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FR9612050601 /* Base */ = {isa = PBXFileReference; name = Base; path = Base.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
|
||||
FR9612050602 /* en */ = {isa = PBXFileReference; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -242,6 +248,8 @@
|
||||
FR1345298501 /* Info.plist */,
|
||||
FR6218091901 /* ViewController.swift */,
|
||||
VG2858723001 /* LaunchScreen.storyboard */,
|
||||
VG5506161801 /* Localizable.strings */,
|
||||
VG1597538701 /* Localizable.stringsdict */,
|
||||
VG3182922801 /* LocalizedStoryboard.storyboard */,
|
||||
VG2043127501 /* Main.storyboard */,
|
||||
);
|
||||
@@ -495,6 +503,8 @@
|
||||
files = (
|
||||
BF3154421201 /* Assets.xcassets in Resources */,
|
||||
BF2445564001 /* LaunchScreen.storyboard in Resources */,
|
||||
BF3371332801 /* Localizable.strings in Resources */,
|
||||
BF4414242001 /* Localizable.stringsdict in Resources */,
|
||||
BF2513089601 /* LocalizedStoryboard.storyboard in Resources */,
|
||||
BF2250910101 /* Main.storyboard in Resources */,
|
||||
);
|
||||
@@ -665,6 +675,15 @@
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
VG1597538701 /* Localizable.stringsdict */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
FR9612050601 /* Base */,
|
||||
FR9612050602 /* en */,
|
||||
);
|
||||
name = Localizable.stringsdict;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
VG2043127501 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
@@ -690,6 +709,15 @@
|
||||
name = LocalizedStoryboard.storyboard;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
VG5506161801 /* Localizable.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
FR3899172901 /* Base */,
|
||||
FR3899172902 /* en */,
|
||||
);
|
||||
name = Localizable.strings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
|
||||
@@ -484,11 +484,11 @@ public class PBXProjGenerator {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getFileReference(path: Path, inPath: Path) -> String {
|
||||
func getFileReference(path: Path, inPath: Path, name: String? = nil) -> String {
|
||||
if let fileReference = fileReferencesByPath[path] {
|
||||
return fileReference
|
||||
} else {
|
||||
let fileReference = PBXFileReference(reference: generateUUID(PBXFileReference.self, path.lastComponent), sourceTree: .group, path: path.byRemovingBase(path: inPath).string)
|
||||
let fileReference = PBXFileReference(reference: generateUUID(PBXFileReference.self, path.lastComponent), sourceTree: .group, name: name, path: path.byRemovingBase(path: inPath).string)
|
||||
addObject(fileReference)
|
||||
fileReferencesByPath[path] = fileReference.reference
|
||||
return fileReference.reference
|
||||
@@ -540,6 +540,21 @@ public class PBXProjGenerator {
|
||||
)
|
||||
}
|
||||
|
||||
func getVariantGroup(path: Path, inPath: Path) -> PBXVariantGroup {
|
||||
let variantGroup: PBXVariantGroup
|
||||
if let cachedGroup = variantGroupsByPath[path] {
|
||||
variantGroup = cachedGroup
|
||||
} else {
|
||||
variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, path.byRemovingBase(path: inPath).string),
|
||||
children: [],
|
||||
name: path.lastComponent,
|
||||
sourceTree: .group)
|
||||
addObject(variantGroup)
|
||||
variantGroupsByPath[path] = variantGroup
|
||||
}
|
||||
return variantGroup
|
||||
}
|
||||
|
||||
func getSources(sourceMetadata source: Source, path: Path, depth: Int = 0) throws -> (sourceFiles: [SourceFile], groups: [PBXGroup]) {
|
||||
// if we have a file, move it to children and use the parent as the path
|
||||
let (children, path) = path.isFile ?
|
||||
@@ -577,52 +592,26 @@ public class PBXProjGenerator {
|
||||
// create variant groups of the base localisation first
|
||||
var baseLocalisationVariantGroups: [PBXVariantGroup] = []
|
||||
if let baseLocalisedDirectory = localisedDirectories.first(where: { $0.lastComponent == "Base.lproj" }) {
|
||||
for path in try baseLocalisedDirectory.children() {
|
||||
let filePath = "\(baseLocalisedDirectory.lastComponent)/\(path.lastComponent)"
|
||||
|
||||
let variantGroup: PBXVariantGroup
|
||||
if let cachedGroup = variantGroupsByPath[path] {
|
||||
variantGroup = cachedGroup
|
||||
} else {
|
||||
variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, filePath),
|
||||
children: [],
|
||||
name: path.lastComponent,
|
||||
sourceTree: .group)
|
||||
variantGroupsByPath[path] = variantGroup
|
||||
|
||||
addObject(variantGroup)
|
||||
groupChildren.append(variantGroup.reference)
|
||||
}
|
||||
|
||||
for filePath in try baseLocalisedDirectory.children() {
|
||||
let variantGroup = getVariantGroup(path: filePath, inPath: path)
|
||||
groupChildren.append(variantGroup.reference)
|
||||
baseLocalisationVariantGroups.append(variantGroup)
|
||||
|
||||
let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, variantGroup.reference), fileRef: variantGroup.reference, settings: nil)
|
||||
allSourceFiles.append(SourceFile(path: path, fileReference: variantGroup.reference, buildFile: buildFile))
|
||||
allSourceFiles.append(SourceFile(path: filePath, fileReference: variantGroup.reference, buildFile: buildFile))
|
||||
}
|
||||
}
|
||||
|
||||
// add references to localised resources into base localisation variant groups
|
||||
for localisedDirectory in localisedDirectories {
|
||||
let localisationName = localisedDirectory.lastComponentWithoutExtension
|
||||
for path in try localisedDirectory.children().sorted { $0.lastComponent < $1.lastComponent } {
|
||||
let filePath = "\(localisedDirectory.lastComponent)/\(path.lastComponent)"
|
||||
|
||||
for filePath in try localisedDirectory.children().sorted { $0.lastComponent < $1.lastComponent } {
|
||||
// find base localisation variant group
|
||||
let name = path.lastComponentWithoutExtension
|
||||
let variantGroup = baseLocalisationVariantGroups.first { Path($0.name!).lastComponentWithoutExtension == name }
|
||||
// ex: Foo.strings will be added to Foo.strings or Foo.storyboard variant group
|
||||
let variantGroup = baseLocalisationVariantGroups.first { Path($0.name!).lastComponent == filePath.lastComponent } ??
|
||||
baseLocalisationVariantGroups.first { Path($0.name!).lastComponentWithoutExtension == filePath.lastComponentWithoutExtension }
|
||||
|
||||
let fileReference: String
|
||||
if let cachedFileReference = fileReferencesByPath[path] {
|
||||
fileReference = cachedFileReference
|
||||
} else {
|
||||
let reference = PBXFileReference(reference: generateUUID(PBXFileReference.self, path.lastComponent),
|
||||
sourceTree: .group,
|
||||
name: variantGroup != nil ? localisationName : path.lastComponent,
|
||||
path: filePath)
|
||||
addObject(reference)
|
||||
fileReference = reference.reference
|
||||
fileReferencesByPath[path] = fileReference
|
||||
}
|
||||
let fileReference = getFileReference(path: filePath, inPath: path, name: variantGroup != nil ? localisationName : filePath.lastComponent)
|
||||
|
||||
if let variantGroup = variantGroup {
|
||||
if !variantGroup.children.contains(fileReference) {
|
||||
@@ -633,7 +622,7 @@ public class PBXProjGenerator {
|
||||
let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference),
|
||||
fileRef: fileReference,
|
||||
settings: nil)
|
||||
allSourceFiles.append(SourceFile(path: path, fileReference: fileReference, buildFile: buildFile))
|
||||
allSourceFiles.append(SourceFile(path: filePath, fileReference: fileReference, buildFile: buildFile))
|
||||
groupChildren.append(fileReference)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user