Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol {
if let files = files {
let xcstringsFiles = files.filter({ $0.isXcstrings })
// For xcstrings we need to parse existing files when localization is changed, otherwise we wont get localization strings from xcstrings files.
Comment thread
serhii-londar marked this conversation as resolved.
Outdated
self.parseXCStrings(files: xcstringsFiles, for: localization, context: context)
let xcstringsParsingKey = self.manifestManager.xcstringsParsingKey(for: localization)
self.parseXCStrings(files: xcstringsFiles, for: xcstringsParsingKey, context: context)
let notXcstringsFiles = files.filter({ !$0.isXcstrings })
let notXcstringsFilesToDownload = notXcstringsFiles.filter { self.manifestManager.hasFileChanged(filePath: $0, localization: localization) }
let xcStringsFilesToDownlaod = xcstringsFiles.filter({ self.manifestManager.hasFileChanged(filePath: $0, localization: self.manifestManager.xcstringsLanguage) })
Expand Down Expand Up @@ -165,7 +166,7 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol {

xcstrings.forEach { filePath in
let download = CrowdinXcstringsDownloadOperation(filePath: filePath,
localization: localization,
localization: manifestManager.xcstringsParsingKey(for: localization),
xcstringsLanguage: manifestManager.xcstringsLanguage,
timestamp: timestamp,
contentDeliveryAPI: contentDeliveryAPI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,28 @@ extension ManifestManager: LanguageResolver {

return languages.first(where: { $0.id == crowdinLocalization })?.iOSLanguageCode
}

/// Returns the language key used inside an xcstrings file for the given iOS localization.
///
/// Standard Crowdin languages use their `osxLocale` as the xcstrings key (e.g. "de", "zh-Hans").
/// Custom languages have an `osxLocale` that acts as the iOS locale folder name (e.g. "tra", "SRXK")
/// but the xcstrings file stores their translations under the BCP 47 locale derived from the
/// custom language's `locale` field (e.g. "to" for "to-To", "sr-XK" for "sr-XK").
Comment thread
serhii-londar marked this conversation as resolved.
Outdated
func xcstringsParsingKey(for localization: String) -> String {
let custom = customLanguages
guard let language = crowdinSupportedLanguage(for: localization),
custom.contains(where: { $0.id == language.id }) else {
// Standard language: the iOS localization is already the xcstrings key.
return localization
}
Comment thread
serhii-londar marked this conversation as resolved.
Outdated
// Custom language: derive the xcstrings key from the locale field.
// Replace underscores with hyphens to get BCP 47 format, then strip a redundant
// region subtag when it matches the language subtag (e.g. "to-To" → "to").
let normalizedLocale = language.locale.replacingOccurrences(of: "_", with: "-")
let parts = normalizedLocale.components(separatedBy: "-")
if parts.count == 2 && parts[0].lowercased() == parts[1].lowercased() {
return parts[0]
}
return normalizedLocale
Comment thread
serhii-londar marked this conversation as resolved.
}
}
Loading