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

Deprecate old strings resources #718

Merged
merged 1 commit into from
Aug 14, 2023
Merged

Deprecate old strings resources #718

merged 1 commit into from
Aug 14, 2023

Conversation

gersonnoboa
Copy link
Contributor

Instead of trying to reuse some old strings, deprecate some other strings, and have them coexist in the same file, I have decided to deprecate the L10n.swift class altogether, and create a new one called Localization.swift. This allows me to remove that horrible abbreviated name, and also make a clear distinction between old and new. With this, all new strings will just go to the Localizable.strings as always, and the Deprecated.strings ones shouldn't be used anymore.

This was done by adding two .stencil files: one that handles adding the @deprecated line to the old file, and a new one that handles ignoring all strings that start with android. This is because on the new way to do strings, the Android-specific ones will start with android.. We could remove these from the file, but this would be manual, some could be missed, and at the moment of this PR, we haven't yet determined how we are going to sync these strings with the strings in the Glia Hub.

Finally, the new Localization.swift file is internal, as opposed to L10n.swift which is public. This is because these strings have changed from being the main way to show strings in the widgets, to being a fallback. Now, the Glia Hub will be the main way to pass strings to the widgets, so there's no need to shoot ourselves in the foot, making this public, and then have to worry about deprecations, as we have to do with L10n.swift.

With this, there's no need to have L10n+BackwardsCompatibility.swift, as the new strings and the old ones are separated entities. However, I still need to do a layer that goes between the strings and the rest of the code, for when the strings have functionality that is not present anymore (example, placeholders for values that now just have the direct value in the string).

In a year, we can easily remove L10n.swift and the associated .stencil file.

MOB-2529

// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum Localization {
internal enum Alert {
internal enum Action {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we could potentially make the indentation bigger to conform to swift standards? As this file can be generated from the command line, it's not a big issue but it would just look better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could take a look, probably there's a parameter.

Copy link
Contributor Author

@gersonnoboa gersonnoboa Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated, apparently there's no way of doing this. In theory, I could modify the stencil so that it has four spaces. This would deviate us greatly from the official one. Wouldn't be the worst but we would have to decide if it's worth it. A benefit of being close to the original is that if they update it, we can just add our few changes easily. What do you think would be best?

swiftgen.yml Outdated Show resolved Hide resolved
@gersonnoboa gersonnoboa changed the base branch from development to custom-locales August 14, 2023 08:52
@gersonnoboa gersonnoboa changed the base branch from custom-locales to development August 14, 2023 11:46
@gersonnoboa gersonnoboa force-pushed the MOB-2529 branch 2 times, most recently from 4aa88d5 to e980848 Compare August 14, 2023 11:53
Instead of trying to reuse some old strings, deprecate some other strings, and
have them coexist in the same file, I have decided to deprecate the `L10n.swift`
class altogether, and create a new one called `Localization.swift`. This allows
me to remove that horrible abbreviated name, and also make a clear distinction
between old and new. With this, all new strings will just go to the
`Localizable.strings` as always, and the `Deprecated.strings` ones shouldn't be
used anymore.

This was done by adding two `.stencil` files: one that handles adding the
`@deprecated` line to the old file, and a new one that handles ignoring all
strings that start with `android`. This is because on the new way to do strings,
the Android-specific ones will start with `android.`. We could remove these from
the file, but this would be manual, some could be missed, and at the moment of
this PR, we haven't yet determined how we are going to sync these strings with
the strings in the Glia Hub.

Finally, the new `Localization.swift` file is `internal`, as opposed to
`L10n.swift` which is public. This is because these strings have changed from
being the main way to show strings in the widgets, to being a fallback. Now, the
Glia Hub will be the main way to pass strings to the widgets, so there's no need
to shoot ourselves in the foot, making this public, and then have to worry about
deprecations, as we have to do with `L10n.swift`.

With this, there's no need to have `L10n+BackwardsCompatibility.swift`, as the
new strings and the old ones are separated entities. However, I still need to
do a layer that goes between the strings and the rest of the code, for when the
strings have functionality that is not present anymore (example, placeholders
for values that now just have the direct value in the string).

In a year, we can easily remove `L10n.swift` and the associated `.stencil` file.

MOB-2529
@gersonnoboa
Copy link
Contributor Author

!merge

@sm-deployer sm-deployer merged commit c298636 into development Aug 14, 2023
1 check passed
@sm-deployer sm-deployer deleted the MOB-2529 branch August 14, 2023 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants