How to get iOS-native localized string resource files into the app bundle

108 views
Skip to first unread message

Brad Aisa

unread,
Jun 6, 2020, 12:48:08 AM6/6/20
to Chromium-dev
We are building on iOS/Chromium, and need to add additional screens that require localization. The Chrome/Chromium GRIT system seems only intended for internal Google use. I just want to create my own file, e.g. MyAppStrings.strings file, that is localized into a set of folders like so, in order to use the iOS-native NSLocalizedString family of macros.
en.lproj
  MyAppString.strings
fr.lproj
  MyAppString.strings
etc.

Is there a way using a ninja/GN macro of some kind to get source .strings files generated into the application bundle?

Thanks!

Sylvain Defresne

unread,
Jun 8, 2020, 4:14:28 AM6/8/20
to baisa....@gmail.com, Chromium-dev
If you already have the localised strings file, you need to add bundle_data target and dependency on those targets. You'll have to create one bundle_data target per locale (due to a limitation of gn source_expansion, see https://crbug.com/608382, bug is marked as WNF as we do not use strings file in Chrome so was not considered important to fix).

Something like this should work:

source_set("target_using_localized_strings") {
  sources = [ ... ]
  deps = [ ":localized_strings" ]
}

_locales = [ "en", "fr", ... ]
group("localized_strings") {
  public_deps = []
  foreach(_locale, _locales) {
    public_deps += [ ":localized_strings_$_locale" ]
  }
}

foreach(_locale, _locales) {
  bundle_data("localized_strings_$_locale") {
    visibility = [ ":localized_strings" ]
    sources = [ "strings/$_locale.lproj/MyAppString.strings" ]
    outputs = [ "{{bundle_resources_dir}}/$_locale.lproj/{{source_file_part}}" ]
  }
}

There is no support to extract the strings from source code and generate the first strings file however (i.e. we do not have tools to parse source code to look for uses of NSLocalizedString macro).

Regards,
-- Sylvain



--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/7bdc97f4-ffb0-4900-8ef6-90fa009833dfo%40chromium.org.

Brad Aisa

unread,
Jun 8, 2020, 3:49:51 PM6/8/20
to Chromium-dev, baisa....@gmail.com
Thanks Sylvain! Worked great!

For anyone else trying this, note that the first source_set is an example intended to represent one of your own source_sets, that is dependent on your custom .strings files -- it is not meant to include any of your string files.
To unsubscribe from this group and stop receiving emails from it, send an email to chromi...@chromium.org.

Sylvain Defresne

unread,
Jun 9, 2020, 4:40:27 AM6/9/20
to baisa....@gmail.com, Chromium-dev
Glad it worked. Yes, the source_set was there to show that the dependency should be on the group, not on all individual bundle_data target.
If you need to have multiple .strings files, then you can consider defining a template to factor common code.
-- Sylvain

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/bfa6e94a-b5c3-4a32-89f7-6da22ef4f4a7o%40chromium.org.

anand agarwal

unread,
Apr 29, 2021, 4:13:30 PM4/29/21
to Chromium-dev, Sylvain Defresne, Chromium-dev, baisa....@gmail.com
I created a set of localizable strings file and kept in folders, created bundle_data target for each localizable string file. I added localized target as a dependency in source_set but still localizable key is not reflecting in my app/screen, it is not picking localizable string. Any help/guidance is really appreciated.
Reply all
Reply to author
Forward
0 new messages