Cocoapods: Process *.lproj/*.strings in resource_bundle.

Created on 5 Dec 2013  Â·  14Comments  Â·  Source: CocoaPods/CocoaPods

My library resources are localized and I'm using resource_bundle include them along nibs and images.

  • If I specify:
    s.resource_bundle = { 'MyResources' => 'Resources/*.{png,xib,strings}' }
    String files are they are processed (resulting _.strings are binary, which is both good for performance and space while also *concealing contents_), but they don't preserve their *.lproj directories and breaks localization (similar to #846).
  • On the other my current workaround:
    s.resource_bundle = { 'MyResources' => 'Resources/*.{png,xib,lproj}' }
    Preserves the *.lproj directories (as in #807) and internationalization works, but then string files are not processed, so they are bigger and less performant.

It would be really nice to have both internationalization work and string files processing.

confirmed

Most helpful comment

I figured it out. I needed to update my CocoaPods code to use a strings table named something other than Localizable (since it was colliding with my app's Localizable.string file) and use NSLocalizedStringFromTableInBundle, giving that name and the resource bundle.

You can see this in action on my UnzipKit repo

All 14 comments

Side question: Are image files processed (e.g. png crush)?

Ok, so after digging in to every way that this might be done, I can't seem to find one that will work consistently via configuration.

I had thought that setting:

s.xcconfig = { "APPLY_RULES_IN_COPY_FILES" => "YES", "STRINGS_FILE_OUTPUT_ENCODING" => "binary" }

Would override the build settings and ensure that the conversion would happen, but it turns out that is just naively copies the .lproj folder without inspecting.

The best option at this time might be to use:

spec.prepare_command = <<-CMD
                       find Resources -name "*.strings" -exec plutil -convert binary1 {} \;
                   CMD

This will convert the strings files correctly before installing them in to the project.

Issue has been confirmed by @davelyon

This is biting me right now with xibs as well as strings within an lproj directory. I've tried:

  s.resource_bundle = { "MyResources" => ["Resources/*.lproj/*.{xib,strings}"] }
  s.preserve_paths = "Resources/*.lproj"

But it results in a single nib and strings file in the resource bundle, rather than nib and strings files in a localized directory. Are there any known workarounds?

@brianpartridge I have some success with just including the directory. So something like

s.resource_bundle = { "MyResources" => ["Resources/*"] }

By doing this, cocoapods would just copy everything in the directory _as is_ without flatten the directory. Now you might have other files in there you don't want to copy over, in that case I suggest you create another folder under Resources (e.g. Resources/Localization) and then just have something like

s.resource_bundle = { "MyResources" => ["Resources/Localization*"] }

Curious if there is a solution in place that works 100% of the time? We have a xib file to ship with our pod that has been localized. The xib sits under Base.lproj, and then translations sit under <lang>.lproj folders in <lang>.strings files. We have been unable to get the pod to work using:

s.resource_bundle = {
    'PodResources' => ['Pod/Resources/**/*.*'],
    'PodResources-Localizations' => ['Pod/Localizations/*.lproj']
}

The error occurs because the localizations bundle can't find the xib. It's copied over under the Base.lproj directory, but when we use loadNibNamed... with the PodResources-Localizations bundle to load it up, it crashes. How do we get the pod to find the xib while also preserving the localizations? Is it not supposed to sit under the Base.lproj?

Any updates on this? Are there any way to put localizable strings to a cocoapod podspec in a way that it would work?

Same here bitten by this and unable to find a solid solution.

This should be resolved in 1.0.0.beta.1

I'm still stuck with it.
I refer to the demo https://github.com/dlinsin/cocoapods-storyboard-sample and use

  s.resource_bundles = {
    'Resources' => ['LocalizationDemo/LocalizationDemo/Resources/**/*.{lproj,storyboard}']
  }

but the directories result is
-Resources
--en.lproj
---LocalizationDemo.strings
--LocalizationDemo.storyboard
--de.lproj
---LocalizationDemo.strings
my cocoapods version is 1.0.1 but the result seem not conform to the changes

Special case interface files to use the XIB or Storyboard name for the variant group when using Base Internationalization.

Could anyone show me a correct usage or demo?

@linlin5910 Have you gotten something to work yet? I'm still finding that when my app calls code that uses a localization inside my Pod library, that the string still isn't localized. I'm using the format that @efirestone recommended:

  s.resource_bundles = {
      'UnzipKit' => ['Resources/**/*']
  }

On disk I have this:

- Resources
-- base.lproj
--- Localizable.strings

What I end up with in the generated Pods project is this (I'm installing from a local path until I get the kinks worked out):

- Development Pods
-- UnzipKit
--- Resources
---- Resources
----- Localizable.strings

I'm running my host app with the "Show non-localized strings" build setting, and when one of the strings appears in a dialog box, it's all caps, indicating it isn't localized.

@efirestone I also tried using just resources instead of resource_bundles and that didn't make a difference either.

I figured it out. I needed to update my CocoaPods code to use a strings table named something other than Localizable (since it was colliding with my app's Localizable.string file) and use NSLocalizedStringFromTableInBundle, giving that name and the resource bundle.

You can see this in action on my UnzipKit repo

My interface internationalization problem had been solved.But the directories are still looked strange.
On disk I have this:

--xibs
---Base.lproj
----MyView.xib
---en.lproj
----MyView.strings

and it on xcode like:

--xibs
---MyView.xib
----MyView.xib(Base)
----MyView.string(English)

then i use

  s.resource_bundles = {
    'Resources' => ['MyProject/Resources/**/*']
  }

after pod update the directories result on xcode like this

--MyView.xib
---MyView.xib(Base)
---MyView.string(English)
--xibs
---Base.lproj
----MyView.xib
---en.lproj
----MyView.strings

shouldn't it only show a variant group named MyView.xib instead of show the .lproj file direct?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marzapower picture marzapower  Â·  3Comments

pallaviMN picture pallaviMN  Â·  3Comments

intelliot picture intelliot  Â·  3Comments

iosdev-republicofapps picture iosdev-republicofapps  Â·  3Comments

hmistry picture hmistry  Â·  3Comments