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

Support explanation attribute for Android string resources #11351

Open
nikclayton opened this issue Apr 5, 2024 · 4 comments
Open

Support explanation attribute for Android string resources #11351

nikclayton opened this issue Apr 5, 2024 · 4 comments
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature. help wanted Extra attention is needed.

Comments

@nikclayton
Copy link

Describe the problem

As far as I can tell -- based on reading https://docs.weblate.org/en/latest/formats.html#format-explanation and https://docs.weblate.org/en/latest/formats.html#format-description -- there's no clear mechanism for adding an explanation for a string's usage to Android string resources.

Describe the solution you would like

Since Android string resources are XML you could define a Weblate specific namespace for Weblate-supported attributes. Then Android string resources could declare this namespace and add Weblate-specific attributes for each string.

For example:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:weblate="http://schemas.weblate.org/android/v1">
  <string name="foo" weblate:explanation="Text that would appear as the explanation for this string in the Weblate UI">...</string>
  ...
</resources>

Describe alternatives you have considered

Adding a comment to the string, e.g.,

  <!-- Text that would appear as the explanation for this string in the Weblate UI -->
  <string name="foo">...</string>

is quite fragile; for example, if Android string resources are moved between different Android project modules it's easy for the comments that are "attached" to the string to get lost.

Since XML provides a standardised mechanism for additional metadata to be attached to elements it seems sensible to use that mechanism, instead of inventing new ad-hoc approaches.

Screenshots

No response

Additional context

This is prompted by noticing translation mistakes in my project. For example, I have a string that looks like this in the source language:

<string name="poll_info_format"> <!-- 15 votes • 1 hour left -->  %1$s • %2$s</string>

The comment's to provide additional context to translators for the contents of the two placeholders (exactly what I'd use the explanation for).

In practice I've seen translators inadvertently corrupt this, so for example the translation becomes:

    <string name="poll_info_format">" &lt;!-- 15 votes • 1 hour left --&gt; %1$s • %2$s"<!-- 15 votes • 1 hour left -->
        %1$s • %2$s</string>

(i.e., the comment markers are stripped and the comment becomes visible text in the app's UI)

@nijel
Copy link
Member

nijel commented Apr 5, 2024

Have you tested that native Android tools (such as lint) won't have problems with additional attributes?

@nikclayton
Copy link
Author

Yes. I've checked:

  • Attributes with custom namespaces are ignored (but preserved) by the Translation Editor in Android Studio
  • Android lint doesn't report any issues with additional attributes
  • There are no errors or warnings when building an app with a string resource file that has attributes with a custom namespace

@nijel nijel added enhancement Adding or requesting a new feature. help wanted Extra attention is needed. backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. labels Apr 10, 2024
@nijel
Copy link
Member

nijel commented Apr 10, 2024

Sounds good, we're already supporting weblate-flags XML attribute (see https://docs.weblate.org/en/latest/formats.html#translation-flags), but using an XML namespace is definitely a better approach. There already is a repository with JSON schemas at https://github.com/WeblateOrg/weblate_schemas/, this could be added there.

Copy link

This issue has been added to the backlog. It is not scheduled on the Weblate roadmap, but it eventually might be implemented.

In case you need this feature soon, please consider helping or push it by funding the development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature. help wanted Extra attention is needed.
Projects
None yet
Development

No branches or pull requests

2 participants