Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Make iOS and OS X SDKs localizable #4783

Merged
merged 11 commits into from
Apr 25, 2016
Merged

Make iOS and OS X SDKs localizable #4783

merged 11 commits into from
Apr 25, 2016

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Apr 21, 2016

This PR makes the iOS and OS X SDKs localizable. It separates strings from logic and establishes some infrastructure for localizing the SDKs, but actually adding localizations or support for a specific localization tool is out of scope for this PR. Also out of scope for this PR is any form of map localization: as explained in #1108, the map’s localization is currently controlled by the style and source; dynamically switching languages would require #837 and potentially more language support in the source. So this PR is about the “chrome” only.

Hard-coded English strings are now wrapped in calls to NSLocalizedStringWithDefaultValue() that pair the English strings with unique identifiers, so that changes to the English strings don’t affect other localizations. In code shared between the iOS and OS X SDKs, the strings come from the “Foundation” table. The NSLocalizedString(), NSLocalizedStringFromTable(), and NSLocalizedStringWithDefaultValue() macros are redefined in NSBundle+MGLAdditions.h to look in the SDK bundle rather than the main application bundle. This redefinition has no effect on the host application, because it’s in an internal header. That header must be included in all files that contain localizable strings. See the header for a full explanation.

Removed the text from the iOS SDK compass view’s image, leaving only the compass plate. A localizable string is drawn atop it at runtime, along the lines of #949. Unlike in that PR, no translations are hard-coded (other than the default English string), and the system font is used.

Added a make rule that runs genstrings and ensures UTF-8 output, since genstrings insists on UTF-16. The encoding is converted in place using the built-in textutil utility. The workflow is that, whenever you add a string that should be localized, you’ll use the NSLocalizedStringWithDefaultValue() macro (making sure to import NSBundle+MGLAdditions.h), run make genstrings, and commit. Eventually, if we start using a localization service, we could use Xcode or xcodebuild to export an XLIFF.

With iOS SDK resources coming from three different directories, the resource-copying part of package.sh has gotten unwieldy. Instead of copying individual resource files around to build the static framework, package.sh now moves Mapbox.bundle into the appropriate directory. Mapbox.bundle is produced by a new build target. Now, when you add a new SDK resource, make sure to add it to both the “dynamic” and “bundle” targets in Xcode.

Replaced $BUNDLE_RESOURCES and $PLACE_RESOURCE_BUNDLES_OUTSIDE_FRAMEWORK with a single variable, $SELF_CONTAINED, that determines whether the output static framework is self-contained – that is, whether it contains Mapbox.bundle, Settings.bundle, and LICENSE.md. Eliminated the ability to produce a static framework that has the same layout as a dynamic framework. Now, resources are always in Mapbox.bundle; self-containment only determines where that bundle resides.

Added a separate source Info.plist to be placed in both the static framework and its resource bundle, but only after we give the build system a chance to expand variables within it. Now nearly all the Info.plist keys are filled in by the build system rather than using plutil in package.sh.

Implemented a localizable CLLocationCoordinate2D formatter in iosapp for use with dropped pin callouts. (Split out into #4802.) Rely on subclasses of MGLPointAnnotation instead of annotation titles to distinguish between different kinds of point annotations.

  • Adopt NSLocalizedString() throughout shared “Foundation” code
  • Improve localizability of coordinate and direction formatters
  • Adopt NSLocalizedString() throughout iOS SDK
  • Adopt NSLocalizedString() throughout OS X SDK
  • Adopt NSLocalizedString() throughout iosapp
    • iosapp requires far more strings than the SDKs for little gain.
  • Pass unique identifiers into NSLocalizedString() and add -a to genstrings
  • Get strings from the SDK bundle instead of the main bundle
  • Add make rule to run genstrings
  • Share formatter localizations between iOS and OS X SDKs
  • Ensure that .strings files use UTF-8 to facilitate diffing and merging
  • Draw iOS compass text at runtime
  • Add Mapbox.bundle target
  • Streamline package.sh
  • Squash 🎃

/cc @friedbunny @boundsj

@1ec5 1ec5 self-assigned this Apr 21, 2016
@1ec5 1ec5 added feature iOS Mapbox Maps SDK for iOS ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Apr 21, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 21, 2016

Translations for the coordinate formats and compass indicator are available for a wealth of languages in the CLDR package (example).

@friedbunny
Copy link
Contributor

Translations for the coordinate formats and compass indicator are available for a wealth of languages in the CLDR package (example).

Coordinate format strings are definitely available (e.g. the ones you linked to, 北緯35度32分 東経135度0分 — N35°32”, E135°0”), though I don’t see the string I would expect for a compass: plain ole 北.

@1ec5
Copy link
Contributor Author

1ec5 commented Apr 21, 2016

That’s true, but I don’t foresee us automatically pulling translations from CLDR, so the choice of compass text would be up to the translator. CLDR would just be a starting point or backfill.

@1ec5 1ec5 force-pushed the 1ec5-l10n-949 branch 4 times, most recently from c206e4f to 8d7b531 Compare April 24, 2016 18:50
@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label Apr 24, 2016
@1ec5 1ec5 changed the title Make SDK and iosapp localizable Make iOS and OS X SDKs localizable Apr 24, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 24, 2016

Since I first filed this PR, I’ve made a number of changes tangentially related to localizability and made the OS X SDK localizable to boot. The additional localization resources forced my hand in refactoring and cleaning up package.sh. I left half a spaghetti dinner in there for anyone who’s interested in cleaning up the rest. 🍝 I’ve rewritten the PR description to walk through all the changes.

With our increased reliance on Xcode for project management, it isn’t clear to newcomers what each target is used for and where each build product ends up. I’ve written up a brief guide to common workflows like adding source code files and resources. Folks who’ve contributed to the iOS or OS X SDKs in the past should also take note of recent workflow changes by reading DEVELOPING.md in the respective platform/ directories.

@1ec5 1ec5 added this to the ios-v3.3.0 milestone Apr 24, 2016
1ec5 added 8 commits April 24, 2016 16:13
Made storyboards and strings throughout the SDK and iosapp localizable. Replaced the compass image with an unlabeled image. Draw a localizable string atop it at runtime.

Redefined NSLocalizedString() and NSLocalizedStringFromTable() macros to look at the SDK bundle rather than the main application bundle. This redefinition has no effect on the host application, because it’s in an internal header. That header must be included in all files that contain localizable strings. See NSBundle+MGLAdditions.h for a full explanation.

Added a make rule that runs genstrings and ensures UTF-8 output (since genstrings insists on UTF-16).

Use MGLCoordinateFormatter in iosapp for dropped pin callouts. Rely on subclasses of MGLPointAnnotation instead of annotation titles to distinguish between different kinds of point annotations.
Long unit style isn’t intended to be spelled out, so the clock and coordinate direction formatters now use numerals for long unit style, differing from medium unit style in less drastic ways. The locale no longer needs to be exposed, since it’ll always match the overall string’s locale. Added support to the coordinate formatter for different unit styles. Made minutes and seconds of arc optional.

Maintain strings for darwin/ formatter classes in a separate Foundation strings table that can be shared between the iOS and OS X SDKs. Added an English .stringsdict override that correctly pluralizes units.

Capitalize osxapp window titles, now that they spell out the directions.
Assigned unique IDs to localizable English strings in code.

Made iosapp non-localizable. For the time being, it isn’t worth the trouble to localize more strings for this demo application than for the SDK itself.
Replaced the iOS-specific ilocalize make rule with a genstrings make rule that creates iOS, OS X, and shared strings files. Moved the override English .stringsdict file under darwin/resources/. Made the default OS X callout view XIB localizable. Made some hard-coded strings in the OS X SDK source localizable.
Added a target that produces Mapbox.bundle.

Replaced $BUNDLE_RESOURCES and $PLACE_RESOURCE_BUNDLES_OUTSIDE_FRAMEWORK with a single variable, $SELF_CONTAINED, that determines whether the output static framework is self-contained – that is, whether it contains Mapbox.bundle, Settings.bundle, and LICENSE.md. Eliminated the ability to produce a static framework that has the same layout as a dynamic framework. Now, resources are always in Mapbox.bundle; self-containment only determines where that bundle resides.

Added a separate source Info.plist to be placed in both the static framework and its resource bundle, but only after we give the build system a chance to expand variables within it. Now nearly all the Info.plist keys are filled in by the build system rather than using plutil in package.sh.
We have a lot of targets now, and it isn’t always clear to new contributors where files end up. Hopefully this brief guide to adding files will help.
@1ec5 1ec5 removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Apr 24, 2016
1ec5 added 3 commits April 24, 2016 16:41
Also converted the bundle’s strings file from UTF-16 encoding to UTF-8 encoding for better diffability.
Added a separate target to produce the example Settings.bundle. Use the build product in iosapp instead of a folder reference.

Added the bundle and settings targets as dependencies on the dynamic and static targets instead of listing them explicitly in various schemes.
@1ec5 1ec5 merged commit c376380 into master Apr 25, 2016
@1ec5 1ec5 deleted the 1ec5-l10n-949 branch April 25, 2016 03:02
1ec5 added a commit that referenced this pull request Apr 25, 2016
Followup to #4783: fixed an issue causing make genstrings to reconvert a UTF-8-encoded file from UTF-16 to UTF-8, garbling it.
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 25, 2016

57f0a21 fixes an issue causing make genstrings to reconvert a UTF-8-encoded file from UTF-16 to UTF-8, garbling it.

1ec5 added a commit that referenced this pull request Apr 25, 2016
Fixed a crash introduced in #4783 that occurs when launching osxapp. -[NSString localizedCapitalizedString] is only available on OS X 10.11 and above.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants