What is the simplest way of adding strings.xml to the Android build target, both for default under res/values/ and for any languages supported under res/values-xx/?
Hi Bjørn,
as described on Build settings page, which contains other useful information too, it should go something like this:
[Require("Android.ResStrings.Declaration", "<string name=\"hello\">Hello!</string>")]
Hi Uldis,
As I understand from the doc, it will add to res/values/strings.xml. What about other languages?
As far as I could see, there is no easy way to do other languages currently.
That same link covers working with UXL files, and you may be able to achieve what you need with CopyFile
as explained in this forum post.
If you’re looking for a way to implement localization, we usually suggest this approach.
Thanks!
We use your suggested approach in general, but this is for localization of text in push notifications. I will try out CopyFile
- seems promising.
Happy to help! Also, just a note - we have logged an internal ticket to investigate the feasibility of creating a wrapper for both Android and iOS implementation on strings.xml
(Android) and .strings
(iOS) support. No promises at this point, but we’ll keep you posted.
For iOS I’ve made a ruby-script adding string resources to the target iOS project, since I couldn’t find a way of doing it on the Fuse-side. It you are interested, I’m sure we can share it.
We’re happy to receive any input on this, yes. A link to a public git repo would be best, or if the code is short and not too sensitive, you could just post it here on the thread.
I will come back to you on that over the weekend.
The following ruby scripts adds a set of localized string resources to an xcode project generated from fuse:
#!/usr/bin/env ruby
require 'fileutils'
require 'xcodeproj'
name = ARGV[0]
xcode_root_path = ARGV[1]
iOS_lang_root_path = ARGV[2]
base_lang = ARGV[3]
begin
extra_items = []
puts 'Copy localized strings to Xcode-project'
base_langItem = base_lang + '.lproj'
Dir.foreach(iOS_lang_root_path) do |item|
next if item.start_with?('.')
isBaseItem = (item.casecmp base_langItem) == 0
source = iOS_lang_root_path + item
if isBaseItem
target = xcode_root_path + name + '/Base.lproj'
puts "... copying from #{source} to #{target}"
FileUtils.copy_entry source, target
else
target = xcode_root_path + name + '/' + item
puts "... copying from #{source} to #{target}"
FileUtils.copy_entry source, target
extra_items.push(item)
end
end
projectpath = xcode_root_path + name + ".xcodeproj"
puts "Opening " + projectpath
proj = Xcodeproj::Project.open(projectpath)
puts 'Adding Localizable.strings variant group'
strings_group = proj.root_object.main_group.new_variant_group('Localizable.strings')
puts "Adding string resources to Localizable.strings variant group"
puts "-- #{name}/Base.lproj/Localizable.strings"
base_strings_path = name + '/Base.lproj/Localizable.strings'
base_strings_file = strings_group.new_file(base_strings_path)
base_strings_file.name = 'Base'
extra_items.each { |item|
extra_strings_path = name + '/' + item + '/Localizable.strings'
puts "-- #{extra_strings_path}"
extra_strings_file = strings_group.new_file(extra_strings_path)
extra_strings_file.name = item.split('.').first
}
puts 'Adding Build File for string group to Resources Build Phase'
resourcesBuildPhase = proj.objects.grep(Xcodeproj::Project::Object::PBXResourcesBuildPhase).first
resourcesBuildPhase.add_file_reference(strings_group)
puts 'Add known regions'
regions = extra_items.map { |x| x.split('.').first }
all_regions = (proj.root_object.known_regions + [base_lang, 'Base'] + regions).uniq
puts "Updated regions #{all_regions.join(', ')}"
proj.root_object.known_regions = all_regions
puts 'Add build setting: CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;'
proj.build_configurations.each do |config|
config.build_settings.store("CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED", "YES")
end
proj.save
puts 'Adding Localizable.strings completed successfully'
rescue => detail
puts detail
abort '*** ERROR: Adding Localizable.strings failed'
end