Skip to content
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

Addition of .string file changes all previous strings usage #1093

Open
jalone87 opened this issue Dec 20, 2023 · 1 comment
Open

Addition of .string file changes all previous strings usage #1093

jalone87 opened this issue Dec 20, 2023 · 1 comment

Comments

@jalone87
Copy link

jalone87 commented Dec 20, 2023

Hello, i have succesfully integrated SwiftGen for string localization with structured-swift5 template (the same happens with flat-swift5).
So far i only had one Localizable.strings file, which with the default template generates items usable in the form L10n.stringKey.

Now tho, i have added an additional InfoPlist.strings file, and ALL the project's strings get moved under L10n.Localizable.stringKey and L10n.InfoPlist.stringKey for the new ones, understandably to distinguish the file source and avoid conflicts. This tho means i have to change hundreds of lines on code on as many files. Some are dynamic and not as easy to change with find/replace. Beside i dont want to re-run all test batteries.

Is there a way to default to have L10n as default for Localizable (and the rest using su contianers/structs)? WHat is the best approach to follow? Is there some parameter i can change or i have to create a custom template/generator?

I would suggest also, to remove this shortcut or make the L10n.Localizable.stringKey form default, since this is bound to happen for most projects i would guess, but i couldn't find a warning.

Thank you

@djbe
Copy link
Member

djbe commented Mar 15, 2024

Well, we try to reduce the friction for most people.

  • In general, a project will only have the one Localizable.strings file. And for all those projects, we'd rather they don't have to write longer translation keys.
  • If a project has multiple files, the built-in templates support this, as you mentioned.

What is an issue is adding a file, and suddenly all your existing keys becoming invalid. Honestly very easy to fix with find/replace, but I can understand the annoyance.

I would not change the default behaviour of the templates though. 2 things you can do:

  • You could create a custom template do not create the "sub-level" for the localizable strings. You could even go as far as flattening them all into the same level. In any case, beware of collisions ⚠️
  • You can set the forceFileNameEnum template option, which will always create the file "level" in the generated code, even with one file. Check the template docs for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants