-
Notifications
You must be signed in to change notification settings - Fork 823
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
Fix localisation variant groups #70
Conversation
Thanks @ryohey, this is great! I actually just added a commit to master that fails the travis test if the generated fixture changes and wasn't committed, but it's after you created your branch |
7e158d5
to
91611e4
Compare
OK thanks! |
Yeah, FixtureTests would be a good place. You can make a new Fixture project, but I think it would just be easier to edit the current |
let fileReference = getFileReference(path: filePath, inPath: path) | ||
groupChildren.append(fileReference) | ||
// create variant groups of the base localisation first | ||
var baseLocalisationVariantGroups = [PBXVariantGroup]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: the rest of the codebase uses var baseLocalisationVariantGroups: [String] = []
syntax
var baseLocalisationVariantGroups = [PBXVariantGroup]() | ||
if let baseLocalisedDirectory = localisedDirectories.first(where: { $0.lastComponent == "Base.lproj" }) { | ||
for filePath in try baseLocalisedDirectory.children() { | ||
let variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, filePath.lastComponent), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass the whole path.string
into generateUUID so it's more deterministic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
if let baseLocalisedDirectory = localisedDirectories.first(where: { $0.lastComponent == "Base.lproj" }) { | ||
for filePath in try baseLocalisedDirectory.children() { | ||
let variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, filePath.lastComponent), | ||
children: Set(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
children can use []. This will also be changing to an array in the next xcodeproj version anyway tuist/XcodeProj#87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
var baseLocalisationVariantGroups = [PBXVariantGroup]() | ||
if let baseLocalisedDirectory = localisedDirectories.first(where: { $0.lastComponent == "Base.lproj" }) { | ||
for filePath in try baseLocalisedDirectory.children() { | ||
let variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, filePath.lastComponent), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if more than 1 target has these files in it's sources? Do the variant groups need to be cached like the groupsByPath
are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. I will add the cache for variant groups.
allFilePaths.append(path) | ||
// find base localisation variant group | ||
let name = filePath.lastComponentWithoutExtension | ||
guard let variantGroup = baseLocalisationVariantGroups.first(where: { Path($0.name).lastComponentWithoutExtension == name }) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if a localised file isn't inside a Base.lproj
? Does this then not add the file reference anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes It will do not add the reference. It can be a problem in the case that resources placed in en.lproj but not in Base.lproj. For example a case an user removed resource in Base.lproj but not one in en.lproj.
I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the project was created in the usual way, it looks like Base.lproj is included.
The project folder should contain one folder named Base.lproj and other language-specific folders with the .lproj extension. The prefix for the language folders is the language ID, as described in Language and Locale IDs.
c720d9e
to
d8aa1e2
Compare
@yonaskolb I fixed issues you reviewed and I ran swift test then commit the updated project, but CI was failure. What should I do? |
Thats interesting. If you've really committed the current version of the generated project I'm not sure why it's generating a different on on travis. |
7ddc1b2
to
a5256f1
Compare
@yonaskolb Thanks I resolved. I used full path to generate UUID. I changed it to remove basePath. Could you review it? |
a0c15a9
to
9cc24bb
Compare
rebased onto master and resolve conflicts |
@yonaskolb are there any problems? |
Hi @ryohey, sorry I haven't had time to look at this in depth. I'll review it as soon as I have some time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍
for path in try localisedDirectory.children().sorted { $0.lastComponent < $1.lastComponent } { | ||
guard fileReferencesByPath[path] == nil else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when multiple targets share localised sources that aren't in a Base.lproj
directory? It looks like the second target won't get a build file, as this path is skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’re right. I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yonaskolb I fixed this. 8596091#diff-2f3c621620623f55e7ff42cc32198a10R540
addObject(variantGroup) | ||
// find base localisation variant group | ||
let name = path.lastComponentWithoutExtension | ||
let variantGroup = baseLocalisationVariantGroups.first(where: { Path($0.name).lastComponentWithoutExtension == name }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: could use trailing closure syntax here
|
||
guard let variableGroup = getVariableGroups(resourceName).first else { throw failure("Couldn't find the variable group") } | ||
|
||
do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just for visual grouping? Otherwise the it
function is throwing so you don't need to wrap in a do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's just for visual grouping.
I rebased this branch, but the code change is only 8596091, which fixed the problem pointed out in the review. |
Nice one @ryohey! 🎉 |
I noticed this only seems to work if the default localization is in |
Actually looks like there might be another issue with this, I get this error on CI:
|
@ryohey, are you able to take a look at this? |
@keith If only one * .lproj other than Base.lproj is included in the project, It does not create a Variant Group but add a reference to the file directly, so I think it's not a problem. However, if there are only en.lproj and ja.lproj, for example, they are added directly, so there is a problem. It's necessary to disable Base Localization to fix the issue but the project currently output by XcodeGen is unconditionally enabled Base Internationalization by specifing Base in
(I just noticed that it might necessary to add the name of * .proj to knownRegions now) If there is no base.lproj, it seems correct to use PBXProject's developmentRegion as Base Language, but developmentRegion is fixed to English, It may be necessary to adding syntax so that it can be specified developmentRegion from spec.
As for the CI warnings please let me know your project's spec because I could not reproduced. |
Here's an example project with the warning. You need to build with the newest commit of XcodeGen for it to work at all. Run |
Awesome thanks so much! |
Add localized resources are added to one variant group.
described in #69