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

Adding files to variants #113

Open
st3fan opened this issue Jan 6, 2017 · 5 comments
Open

Adding files to variants #113

st3fan opened this issue Jan 6, 2017 · 5 comments

Comments

@st3fan
Copy link

st3fan commented Jan 6, 2017

(I know this is not really a bug report, but I don't know where else to ask questions - I'm happy to convert this into a wiki page as an example usage though)

Hello and thank you for maintaining this project. At Mozilla we are trying to use this for the following use case:

We have a product called Focus at https://github.com/mozilla-mobile/focus which currently is English only.

We localize the product by exporting an en.XLIFF file to our localization volunteers and we get back XLIFF files for other locales. To import these we run xcodebuild -importLocalizations -localizationPath l10n/nl.xliff for example. This spits out .strings files in the proper .lproj directories.

The problem is that xcodebuild only generates the files. It does not actually add them to the project.

This is where pbxproj comes in. I'd like to use it to find for example the PBXVariantGroup for Localizable.strings and then add a PBXFileReference reference for it.lproj/Localizable.strings to it.

However, we are lost in the complexity of both the Xcode projects and the pbxproj API.

My question to you is if we can get some help to find out how to do this. I'm happy to turn the end result in some reusable code that anyoen can use. Or a blog post or a wiki page.

🧀

@kronenthaler
Copy link
Owner

Hello @st3fan,
Sounds like an interesting case that i never have dealt with. Xcode project format doesn't have an official spec, so the way pbxproj has been built is by reverse engineering the format. What i usually do when a new case appear is the following:

  1. create the new xcode project, the simplest you can find (for iOS, single view application is what i use the most)
  2. save the project.pbxproj somewhere to diff it after the change
  3. do the change you want achieve in Xcode manually.
  4. compare the saved project.pbxproj with the one after your changes.

Based on that sequence, i can determine what new sections were created and how they are linked to one another.

The PBXVariantGroup it's not defined and probably will have some special logic that have to be dealt with.

I'm more than happy to do this for you guys if you send over the project.pbxproj after the changes have been done manually. :)

@st3fan
Copy link
Author

st3fan commented Jan 9, 2017

Awesome. We really appreciate the help.

This is what I did:

  • Go to the Blockzilla Project settings and add Italian as a locale
  • Run xcodebuild -importLocalizations -localizationPath focusios-l10n/it/focus-ios.xliff -project Blockzilla.xcodeproj

Attached are the projects files before and after. The -importLocalizations did not result in any project changes. Just the files being updated.

Git status:

On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   Blockzilla/it.lproj/InfoPlist.strings
	new file:   Blockzilla/it.lproj/Localizable.strings

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   Blockzilla.xcodeproj/project.pbxproj
	modified:   Blockzilla/it.lproj/InfoPlist.strings
	modified:   Blockzilla/it.lproj/Localizable.strings

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	ContentBlocker/it.lproj/
	XCUITest/it.lproj/

Diff of the project file:

diff -Bub ~/Desktop/Focus1BeforeAddingLocale.pbxproj  ~/Desktop/Focus2AfterAddingLocale.pbxproj
--- /Users/sarentz/Desktop/Focus1BeforeAddingLocale.pbxproj	2017-01-09 12:59:01.000000000 -0500
+++ /Users/sarentz/Desktop/Focus2AfterAddingLocale.pbxproj	2017-01-09 13:00:06.000000000 -0500
@@ -241,6 +241,8 @@
 		E47F9AE91DB9329D00A93285 /* Adjust-Focus.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Adjust-Focus.plist"; sourceTree = "<group>"; };
 		E47F9AEB1DB9333200A93285 /* Adjust-Klar.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Adjust-Klar.plist"; sourceTree = "<group>"; };
 		E47F9AED1DB9338600A93285 /* AdjustIntegration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdjustIntegration.swift; sourceTree = "<group>"; };
+		E4BCCD041E24071800BBAAA7 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		E4BCCD051E24071800BBAAA7 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
 		E4BF2DD31BACE8CA00DA9D68 /* Klar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = Klar.app; path = "Firefox Klar.app"; sourceTree = BUILT_PRODUCTS_DIR; };
 		E4BF2DD61BACE8CA00DA9D68 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
 		E4BF2DDD1BACE8CA00DA9D68 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -603,6 +605,7 @@
 				en,
 				Base,
 				de,
+				it,
 			);
 			mainGroup = E4BF2DCA1BACE8CA00DA9D68;
 			productRefGroup = E4BF2DD41BACE8CA00DA9D68 /* Products */;
@@ -807,6 +810,7 @@
 			children = (
 				D343DCC31C44356500D7EEE8 /* de */,
 				D362D26A1C47326A0041980A /* en */,
+				E4BCCD051E24071800BBAAA7 /* it */,
 			);
 			name = Localizable.strings;
 			sourceTree = "<group>";
@@ -832,6 +836,7 @@
 			children = (
 				E40AFC791DDDE98300DA5651 /* en */,
 				D3C70C671DDE795300CEE458 /* de */,
+				E4BCCD041E24071800BBAAA7 /* it */,
 			);
 			name = InfoPlist.strings;
 			sourceTree = "<group>";

Zip file containing both project files:

AddingLocaleToProject.zip

@kronenthaler
Copy link
Owner

Thanks for the files, i took a look at the way Xcode imports the files, and i saw some funny behaviors when importing the .xliff file with the Editor > Import localization menu.

Note to self: so far, this is what i manage to gather:
- special folder .lproj
- has to add all items under the .lproj folder into the PBXFileReference section
- create if not exist a PBXVariantGroup with the name of the file under .lproj
- get the PBXVariantGroup created (or existing) and add the fileRef's id as a children
- add the PBXVariantGroup in the buildFile section as a resource build phase of the target

I will try to tackle this this week/weekend.

@kronenthaler
Copy link
Owner

@st3fan i have some proposed changes #116 , can you verify it works for what you need?

@Rex-Appier
Copy link

Rex-Appier commented Dec 18, 2020

PBXVariantGroup

Is this feature done or included in current stable build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants