gpt4 book ai didi

resources - CocoaPods 添加语言环境的子规范

转载 作者:行者123 更新时间:2023-12-03 08:17:44 27 4
gpt4 key购买 nike

我有一个共享代码的 podspec 并且我包含了所有语言环境,但是当 Podspec 的用户只需要一个子集时,他们会将他们的应用程序本地化为所有语言。

我想只允许指定子集,例如只指定英语。但我似乎无法让这种行为发挥作用。有什么建议吗?

Podfile 使用示例

# Just English languages
pod 'MyStuff', '2.4.0'
pod 'MyStuff/en', '2.4.0'
pod 'MyStuff/en-GB', '2.4.0'

MyStuff.podspec 的示例 Podspec
Pod::Spec.new do |s|
s.name = 'MyStuff'
s.version = '2.4.0'
s.summary = "MyStuff for iOS."
s.source = {
:git => 'somewhere',
:tag => s.version.to_s
}
s.public_header_files = ['**/**/MyView.h', ...]

s.source_files = ['MyStuff/*.{h,m}' ]

s.resources = ['MyStuff/Resources/*.{png,xib}',
'MyStuff/config.plist']

s.platform = :ios, '5.0'
s.requires_arc = true
s.frameworks = 'CoreGraphics', 'Foundation', 'QuartzCore', 'SystemConfiguration', 'UIKit'

# All locales
s.subspec "all" do |all|
all.resources = ['MyStuff/localization/**']
all.preserve_paths = ['MyStuff/localization/**']
end

# Just en locale
s.subspec "en" do |en|
en.resources = ['MyStuff/localization/en.lproj']
en.preserve_paths = ['MyStuff/localization/en.lproj']
end

# Just en-GB locale
s.subspec "en-GB" do |enGB|
enGB.resources = ['MyStuff/localization/en-GB.lproj']
enGB.preserve_paths = ['MyStuff/localization/en-GB.lproj']
end

# Just fr locale
s.subspec "fr" do |fr|
fr.resources = ['MyStuff/localization/fr.lproj']
fr.preserve_paths = ['MyStuff/localization/fr.lproj']
end

# I have many other locales left out here for brevity.
end

最佳答案

你会想要使用 嵌套子规范​​ default_subspec

# All is default (pod 'PodName/Locale' or pod 'PodName')

s.subspec "Locale" do |l|
l.default_subspec 'All'

l.subspec "All" do |en|
en.resources = 'MyStuff/localization'
en.preserve_paths = 'MyStuff/localization'
end

l.subspec "en" do |en|
en.resources = 'MyStuff/localization/en.lproj'
en.preserve_paths = 'MyStuff/localization/en.lproj'
end

l.subspec "en-GB" do |en|
en.resources = 'MyStuff/localization/en-GB.lproj'
en.preserve_paths = 'MyStuff/localization/en-GB.lproj'
end

l.subspec "en-US" do |en|
en.resources = 'MyStuff/localization/en-US.lproj'
en.preserve_paths = 'MyStuff/localization/en-US.lproj'
end
end

然后在应用程序的 Podfile 中:

pod 'PodName/Locale/en-GB'
pod 'PodName/Locale/Klingon'
pod 'PodName/Locale/Yoda'

更多:
  • CocoaPod docs
  • Example podspec with subspecs

  • 奖金黑客

    %w|en en-GB en-US|.map {|localename|
    l.subspec localename do |loc|
    loc.resources = "PodPath/To/Localization/#{localename}.lproj"
    loc.preserve_paths = "PodPath/To/Localization/#{localename}.lproj"
    end
    }

    关于resources - CocoaPods 添加语言环境的子规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16430413/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com