Weblate: Component discovery addon name replace

Created on 6 Jun 2018  路  6Comments  路  Source: WeblateOrg/weblate

I would like in component discovery addon to have more control over component's name composition if possible. I have a situation where components names are with dashes and for nice name would be better to have them space separated. However there is no replace built-in modifier in django and there is also lack of multiple input arguments support.

Therefore the easiest solution seems to me to implement some split modifier and then use it together with join. Code sample below.

@register.filter
def splitby(value, sep=" "):
    """
    Splits the input string `value` by given `sep` separator.
    """
    return value.split(sep)

# component name adjust template
{{ component | splitby:"-" | join:" " | capfirst }}

The remaining questions are where to put the splitby modifier code and is it a good approach overall?

enhancement good first issue help wanted

All 6 comments

Alternative approach would be to define function for the template and do the replacement in that (however that would not allow chaining with other filters):

{% replace component "-" " " %}

Anyway either of these would have to be registered in the custom render engine:

https://github.com/WeblateOrg/weblate/blob/e6d951653a4bf2ba898a62c17284f1c469898a8a/weblate/utils/render.py#L29-L36

Is this an issue that can be assigned to a new contributor? I would like to work on it.

Yes, you're welcome to work on this. It's technically not possible to assign issue on GitHub to non member though.

Alright. Just to be clear, what I am supposed to do here is create spaces between the generated names, and capitalize the first letter of each word?

The goal is to be able to replace chars in the name. I see several approaches to implementing:

I slightly prefer the tag approach as it's easier to understand. Also it can be actually used with filers:

{% replace component|capfirst "-" " " %}

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see problem with the fix, please comment on this issue.
  • In case you see similar problem, please open separate issue.
  • If you are happy with the outcome, consider supporting Weblate by donating.
Was this page helpful?
0 / 5 - 0 ratings