简体   繁体   English

iOS - 本地化字符串在 pod 中不起作用

[英]iOS - Localized string doesn't work in pod

I'm working on creating 2 new pods for my company, but one of them decides to act up and doesn't localize strings at all, instead, it returns the keys.我正在为我的公司创建 2 个新 pod,但其中一个决定采取行动并且根本不本地化字符串,而是返回键。 They have pretty much the same podspec for both (I simply clone one and change the name).它们的 podspec 几乎相同(我只是克隆了一个并更改了名称)。 I set a break point and tried to print out the Bundle po Bundle(path: path) , this is what I got:我设置了一个断点并尝试打印出 Bundle po Bundle(path: path) ,这就是我得到的:

- some : NSBundle </var/containers/Bundle/Application/62C0534D-6CRE-40AE-9C2A-574BF212A4AE/AppName.app/PodName.bundle/en.lproj> (not yet loaded)

Print out the string with this: po Bundle(path: path)?.localizedString(forKey: key, value: "", table: table)?? ""用这个打印出字符串: po Bundle(path: path)?.localizedString(forKey: key, value: "", table: table)?? "" po Bundle(path: path)?.localizedString(forKey: key, value: "", table: table)?? "" gives me the value of key (table = PodName). po Bundle(path: path)?.localizedString(forKey: key, value: "", table: table)?? ""给了我key的值(表 = PodName)。

Print out the resource path po Bundle(path: path)?.path(forResource: "PodName", ofType: "strings") gives me nil (the string file name is the same as pod name).打印出资源路径po Bundle(path: path)?.path(forResource: "PodName", ofType: "strings")给我 nil (字符串文件名和 pod 名一样)。 The other pod I have has a valid path for the resource.我拥有的另一个 pod 具有资源的有效路径。

I check on the other pod, see everything is exactly the same, except for the pod name, and it works.我检查了另一个 pod,发现一切都完全相同,除了 pod 名称,它工作正常。 Other teams' pods use the same pattern to localize strings as well and they all work.其他团队的 pod 也使用相同的模式来本地化字符串,并且它们都可以工作。 If I put the strings extension into resource_bundles, it won't load the first time, but if I load the screen again, correct strings will show up.如果我将strings扩展名放入 resource_bundles,它不会第一次加载,但如果我再次加载屏幕,则会显示正确的字符串。

In the main project I can even see the strings files get downloaded into Resource folder of the pod.在主项目中,我什至可以看到字符串文件被下载到 pod 的 Resource 文件夹中。

Here is the podspec that I have:这是我拥有的 podspec:

Pod::Spec.new do |spec|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.name         = "PodName"
  spec.version      = "20.7.1"
  spec.summary      = "PodName"
  spec.description  = <<-DESC
PodName
                   DESC

  spec.homepage     = "example.com"

  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.license      = { :type => "GNU GPLv3", :file => "LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.author             = { "My Name" => "my.email@example.com" }

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.platform     = :ios, "10.0"

  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.source       = { :git => "the git url", :tag => "#{spec.version}" }

  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  spec.requires_arc = true
  spec.static_framework = true

  spec.subspec 'Core' do |sp|
    sp.source_files  = "PodName", "PodName/**/*.{h,m,swift}"
    sp.public_header_files = "PodName/**/*.h"
    sp.preserve_paths = 'PodName/**/*.lproj/*.strings'
    sp.resource_bundles = {
      'PodName' => ['PodName/**/*.{lproj,storyboard,xib,xcassets,json,imageset,png}']
    }
  end

  spec.subspec 'Device' do |sp|
    sp.dependency 'PodName/Core'
    sp.vendored_frameworks = "Device/FrameworkA.framework","Device/FrameworkB.framework"
  end

  spec.subspec 'Simulator' do |sp|
    sp.dependency 'PodName/Core'
    sp.vendored_frameworks = "Simulator/FrameworkA.framework","Simulator/FrameworkB.framework"
  end

spec.dependency 'A'
spec.dependency 'B'
spec.dependency 'C'
spec.dependency 'D'

end

Did you check Target Membership for Localized file with your Framework?您是否使用您的框架检查了本地化文件的目标成员资格?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM