-
Notifications
You must be signed in to change notification settings - Fork 131
Introduce BUILD_ONLY_KNOWN_LOCALIZATIONS build setting #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,4 +179,61 @@ public extension RegionVariable { | |
| let installLocLanguages = Set(scope.evaluate(BuiltinMacros.INSTALLLOC_LANGUAGE)) | ||
| return installLocLanguages.isEmpty || installLocLanguages.contains(regionVariantName) | ||
| } | ||
|
|
||
| /// When the build setting `BUILD_ONLY_KNOWN_LOCALIZATIONS` is active, | ||
| /// this region must be present in the project's known localizations | ||
| /// or else the file should not be built. | ||
| /// | ||
| /// `delegate` is used to emit a note about skipping this file if the | ||
| /// method returns `false`. | ||
| /// | ||
| /// - Returns: `true` if this file can be built because | ||
| /// `BUILD_ONLY_KNOWN_LOCALIZATIONS` is disabled, or the file's region | ||
| /// is present in the project's supported localizations. | ||
| /// If this file should not be built, `false` is returned. | ||
| func buildSettingAllowsBuildingLocale(_ scope: MacroEvaluationScope, in project: Project?, _ delegate: (any DiagnosticProducingDelegate)?) -> Bool { | ||
|
|
||
| guard let project else { | ||
| // We can't find the project. Allow the file to build: | ||
| return true | ||
| } | ||
|
|
||
| // Don't apply the BUILD_ONLY_KNOWN_LOCALIZATIONS setting | ||
| // for installloc, because installloc's languages have priority: | ||
| let isInstallloc = scope.evaluate(BuiltinMacros.BUILD_COMPONENTS).contains("installLoc") | ||
| guard !isInstallloc else { | ||
| // We're in the installloc build phase, and we're not interested | ||
| // in changing its behavior. Allow the flow to continue: | ||
| return true | ||
| } | ||
|
|
||
| guard scope.evaluate(BuiltinMacros.BUILD_ONLY_KNOWN_LOCALIZATIONS) else { | ||
| // Build setting is off, this should build: | ||
| return true | ||
| } | ||
|
|
||
| guard let knownLocalizations = project.knownLocalizations, !knownLocalizations.isEmpty else { | ||
| // We can't read the supported localizations, allow it to build: | ||
| return true | ||
| } | ||
|
|
||
| guard let regionVariantName else { | ||
| // Unable to get a region name, allow it to built: | ||
| return true | ||
| } | ||
|
|
||
| if regionVariantName == "mul" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it is |
||
| // Allow mul.lproj (multi-lingual) which is used when xcstrings are paired with IB files: | ||
| return true | ||
| } | ||
|
|
||
| if knownLocalizations.contains(regionVariantName) { | ||
| // This is a known locale, allow it to build: | ||
| return true | ||
| } | ||
|
|
||
| // This region is not supported, so it shouldn't build. | ||
| delegate?.note("Skipping .lproj directory '\(regionVariantName).lproj' because '\(regionVariantName)' is not in project's known localizations (BUILD_ONLY_KNOWN_LOCALIZATIONS is enabled)") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to look into specifying file paths for diagnostics like this. I don't mean in the message, but rather as part of the diag instance. |
||
| return false | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just heads up that messages like this are going to show up for every xcstrings file, although in this particular case the specific file is not provided. Not saying it needs to be provided, but may appear as duplicate messages. Also for IB Compiler, etc.