Search code examples
androidioslocalizationweblate

How can I limit a Weblate check/autofix on the file format (i.a. Android, iOS)


We use Weblate in our mobile app CI environment. So far everything is awesome. Weblate runs in a docker environment (v4.1)

Now I want to improve the workflow.

I managed to create custom checks, these validate the use of Android/iOS placeholders (see sample below). Now the translator needs to know which platform he is working with to use the correct placeholder and dismiss the false-positive check.

Placeholder in use right now are %1$@ for iOS and %1$s for Android

My question:

  • Is there a better/general approach how I can teach my translators how to write placeholders?
  • How can I write my check based on the file format (or translation file suffix, i.e .xml, .strings)? So I know, this is an android/xml file, and the placeholder should be %1$s NOT %1$@

Sample check

class iOSPlaceholderCheck(TargetCheck):
    # Used as identifier for check, should be unique
    # Has to be shorter than 50 characters
    check_id = "iOSPlaceholder"

    # Short name used to display failing check
    name = _("iOS placeholder")

    # Description for failing check
    description = _("Your translation contains an iOS placeholder")

    # Real check code
    def check_single(self, source, target, unit):
        if "%1$@" in target:
            return True
...

thanks in advance


Solution

  • I can see few approaches:

    • In case these formats are generic to the file format, file a feature request so that it's included in future Weblate releases
    • In case this affects just few strings, you can define the placeholders, you can utilize generic placeholders check in Weblate and let Weblate check and highlight them
    • To limit check triggering only on some components, you can use translation flags, these can be set at component level
    • In case you want to write custom check, it should probably also check if the format string is present in the source string, so something like:
    if "%1$@" not in source:
        return False
    return "%1$@" not in target