R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Change default language used for strings

Open SergioCardenas-Santex opened this issue 3 years ago • 8 comments

Is there a more generic way to set the language used by strings?

I'm in a project that is recently adding i18n and was already using R.swift. I also know that we can do it so by replacing our strings from R.string.content.generatedName() to R.string.content.generatedName(preferredLanguages: ["es"])

The problem is we would need to change hundreds of strings manually. Instead, I would like to change hostingBundle or applicationLocale, which are both fileprivate static let. Could we have a method added to change one or both of those variables?

SergioCardenas-Santex avatar Jul 02 '21 16:07 SergioCardenas-Santex

Prefer to add global settings for string language

skeyboy avatar Jul 08 '21 10:07 skeyboy

did u find a solution for the above ?

shadyk avatar Nov 11 '21 13:11 shadyk

Any update on this?

mithilesh-parmar avatar Nov 17 '21 13:11 mithilesh-parmar

@SergioCardenas-Santex what did you do from your side ?

shadyk avatar Nov 22 '21 10:11 shadyk

@mithilesh-parmar what did you do from you side?

shadyk avatar Dec 05 '21 14:12 shadyk

@shadyk I changed all strings in my codebase.

  • Made an extension on Array

extension Array where Element == String { static var preferredLanguageCode: [String] { [ // user preferred language code ] } }

  • Changed all strings to

R.string.localizable.someString(preferredLanguages: .preferredLanguageCode)

mithilesh-parmar avatar Dec 05 '21 14:12 mithilesh-parmar

@mithilesh-parmar I was trying to escape this solution 😞. Thanks anyway.

if the creators can change the hosting bundle's access control to public it will be great

shadyk avatar Dec 06 '21 14:12 shadyk

Yeah I know if there was a way to change hosting bundle it would have been great. But I had to ship my app and could not find any solution so changed all the strings in codebase. @shadyk

mithilesh-parmar avatar Dec 06 '21 14:12 mithilesh-parmar