This script is designed to work in a specific case when you have an enum to access localizble files as a buffer layer
in ConstantTexts.swift
enum ConstantTexts: String {
case mainScreenTitle = "main_screen_title"
}
in Base.lproj/Localizable.strings
"main_screen_title" = "Your app title";
in ar.lproj/Localizable.strings
"main_screen_title" = "عنوان التطبيق";
and so on for other languages
- Determines unused localization keys by scanning Swift files in the project.
- Optionally removes unused keys from the specified language file.
- Creates a backup of the original language file before removal.
- Swift installed on your machine.
- add strings-sweeper.swift anywhere
- open terminal
- change directory to the folder where you add strings-sweeper.swift
(cd path/to/strings-sweeper.swift
) - run the following command after replacing paths with your paths:
swift strings-sweeper.swift --langEnum **/path/to/localization/enum/ConstantTexts.swift** --lang **/path/to/localization/folder/Localization** --remove
Replace /path/to/localization/enum/ConstantTexts.swift
with the actual path to your enumKyes.strings file.
Replace /path/to/localization/folder/Localization
with the actual path to your localizable folder.
The --remove
flag is optional and will automatically remove unused keys from the file.
swift strings-sweeper.swift --langEnum /Users/abdulrahmanqasem/Desktop/Abdulrahman/baaz_ios_new/Baaz/Baaz/Helpers/ConstantTexts.swift --lang /Users/abdulrahmanqasem/Desktop/Abdulrahman/baaz_ios_new/Baaz/BaaziOS/Resources/Localization --remove
inspired by: Strings Sweeper
سخ