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

Refactor localized string definitions #744

Open
Clstroud opened this issue May 9, 2024 · 0 comments
Open

Refactor localized string definitions #744

Clstroud opened this issue May 9, 2024 · 0 comments

Comments

@Clstroud
Copy link
Collaborator

Clstroud commented May 9, 2024

History

Previously, we defined them as .strings files to have more detailed comments for translators and detailed keys to identify each string uniquely. This kept our code footprint relatively small, as it only required referencing the key and allowing the localization import/export engine to handle the rest.

Fast-forward to 2024, and Apple has given us new APIs and tools that make this process much better. However, there are a few wrinkles we need to design around. Part of the solution is shifting how we think about these definitions and, more importantly, what is required to support them on the translation side.

Future direction

Apple suggests we should define these strings in code as much as possible. Currently, we only reference them in code. We need a pattern for structuring the ontology of strings without making them burdensome to consume. Declaring them inline is historically not preferred because elaborate keys and comments take up considerable space in the editor.

Make better use of tables

Let's consider having a 1:1 mapping between screens and their accompanying translations. There are cases where this breaks down (utility classes that are shared between screens, for example), but in general, let's assume that SettingsViewController.swift can have an accompanying SettingsViewController.xcstrings file. This should make creating unique keys much more manageable with less verbosity/namespacing required.

Reflecting the tables in code

The specifics are worth discussing, but for starters, we could consider an additional file, SettingsViewController+Strings.swift, that pairs with the .xcstrings file. The goal would be for it to act as the source of truth for the .xcstrings file in the way Apple intends. The challenge is how we populate that file to create a pattern for consumption in the UI. In past projects, I have attempted to use extensions, type-specialization, and several other things to try and solve this problem satisfactorily. If we undertake a migration in Vocable, I would like to find an idiomatic solution that is minimal in its design and pleasant to consume.

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

No branches or pull requests

1 participant