alunny / node-xcode

tools and utilities for working with xcode/ios projects
Apache License 2.0
226 stars 105 forks source link

PBXVariantGroup??? Need it for localization of App Name in a Cordova Project. #62

Open chrisschmidtmoven opened 9 years ago

chrisschmidtmoven commented 9 years ago

Hi All,

I have a requirement for my App to support English and French. We have an automated build process that I must follow. My problem is that I have to add the localization files to the XCode project when I add the platform. I want to copy the new files in the configure the XCode project using a Cordova hook.

Using https://github.com/alunny/node-xcode

Problem is that the NodeJS xcode project does not add the proper group for this. It should look like this in

/* Begin PBXVariantGroup section / 431B8CD01B77C6EC00AFEDAE / InfoPlist.strings / = { isa = PBXVariantGroup; children = ( 431B8CCF1B77C6EC00AFEDAE / en /, 431B8CD11B77C6EE00AFEDAE / fr /, ); name = InfoPlist.strings; sourceTree = ""; }; / End PBXVariantGroup section */

I added a method to XCode NodeJS called:

pbxProject.prototype.addPbxVariantGroup = function (filePathsArray, name, path, sourceTree) {

console.log('addPbxVariantGroup');
var groups = this.hash.project.objects['PBXGroup'],
    pbxGroupUuid = this.generateUuid(),
    commentKey = f("%s_comment", pbxGroupUuid),
    pbxGroup = {
        isa: 'PBXVariantGroup',
        children: [],
        name: name,
        //path: path,
        sourceTree: sourceTree ? sourceTree : '"<group>"'
    },
    fileReferenceSection = this.pbxFileReferenceSection(),
    filePathToReference = {};

console.log(groups);
/*for (var key in fileReferenceSection) {
    // only look for comments
    if (!COMMENT_KEY.test(key)) continue;

    var fileReferenceKey = key.split(COMMENT_KEY)[0],
        fileReference = fileReferenceSection[fileReferenceKey];

    filePathToReference[fileReference.path] = {fileRef: fileReferenceKey, basename: fileReferenceSection[key]};
}*/

for (var index = 0; index < filePathsArray.length; index++) {
    var filePath = filePathsArray[index],
        filePathQuoted = "\"" + filePath + "\"";
    if (filePathToReference[filePath]) {
        pbxGroup.children.push(pbxGroupChild(filePathToReference[filePath]));
        continue;
    } else if (filePathToReference[filePathQuoted]) {
        pbxGroup.children.push(pbxGroupChild(filePathToReference[filePathQuoted]));
        continue;
    }

    var file = new pbxFile(filePath);
    file.uuid = this.generateUuid();
    file.fileRef = this.generateUuid();
    this.addToPbxFileReferenceSection(file);    // PBXFileReference
    //this.addToPbxBuildFileSection(file);        // PBXBuildFile
    pbxGroup.children.push(pbxGroupChild(file));
}

if (groups) {
    console.log('Adding Groups...')
    groups[pbxGroupUuid] = pbxGroup;
    groups[commentKey] = name;
}

return {uuid: pbxGroupUuid, pbxGroup: pbxGroup};

}

But it does not add it. The group I need does not exist, therefore it does not add it.

Maybe I am overthinking this or missed an easier way to do this. Anyone have a way to add a hook that lets the App Name be displayed in the language of the device???

Thanks,

Chris

toshanmugaraj commented 8 years ago

1) add pbxvariantgroup with the file name. 2) add files from different *.lproj folder to this variantgroup.

More discussion on this issue can be found here, but with ruby. https://github.com/CocoaPods/Xcodeproj/issues/85#issuecomment-146300179