Экспорт локализаций в Xcode 10


#1

До этого делал локализацию текста в коде через extension типа String

extension String {
var localized: String {
    return NSLocalizedString(self, comment: "")
}

}

код выглядел более опрятно и понятно. Но теперь в xCode 10 это почему-то не работает! При экспорте не появлются сторки, отработанные через такой extension, а экспортируются строки, созданные только непосредственно через NSLocalizedString… Кто-то сталкивался с такой проблемой? Или тепреь весь код переписывать? :frowning:


#2

у меня этот код работает в xcode10
возможно что у вас этот файл не установлен в текущий таргет


#3

Так дело в том, что локализации были уже и Файлы strings были. И при добавлении нового функционала на xCode 10 новый строки при использования расширения не экспортировались, хотя в localization catalog в папке с исходниками они были видны… Именно не происходил экспорт в xliff файл. А при использовании непосредственно NSLocalizedString - экспорт происходит …
Удалил все локализации, почистил папку билда, по-новому создал локализации уже с изменениями и всё равно расширение не работает. И ещё один новый стационарный ярлык из сториборда не экспортируется…

остаётся переставить xCode :wink:

Написал, на всякий случай, в эппл в баг-репорт :slight_smile:


#4

Эпл ответили на мой баг-репорт. Стандартно: «не баг, а фича» ))
Как я понял, для точного определения строк, необходимых для экспорта локализаций, нужно использовать только NSLocalizedString! Функции и методы теперь не работают. Не объяснили они, правда, почему в xCode 9 всё нормально работало ))

Engineering has determined that this issue behaves as intended based on the following information:

It has long been a requirement (though not an enforced one) that the arguments to NSLocalizedString be string literals rather than variables. This is because the parsing used to extract strings from source code for localization is simple, and cannot do things like follow variable or function references; even if it were not simple in this fashion, generally determining the intent of your source code would not be possible.

You can write your extension using Bundle.main.localizedString(forKey: self, value: nil, table: nil) in place of NSLocalizedString(self, comment: “”), which is what NSLocalizedString() is a wrapper for in the first place.

Note that this will still not allow code like “some string”.localized to be picked up by Export For Localization; as stated, introspecting your source code to determine intent in that fashion is not generally possible. For Export For Localization to find localized strings, they must be in NSLocalizedString() or another function with congruent arguments; there is a build setting you can use to specify the names of additional macros/functions you would like Export For Localization to pick up.

We consider this issue closed. If you have any questions or concern regarding this issue, please update your report directly (https://bugreport.apple.com).

Thank you for taking the time to notify us of this issue.

Best Regards,

Developer Bug Reporting Team
Apple Worldwide Developer