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

Character Count 'count message' cannot be customised or translated #1681

Closed
36degrees opened this issue Dec 19, 2019 · 15 comments
Closed

Character Count 'count message' cannot be customised or translated #1681

36degrees opened this issue Dec 19, 2019 · 15 comments

Comments

@36degrees
Copy link
Contributor

The Character Count contains hardcoded English strings in both the template:

text: 'You can enter up to ' + (params.maxlength or params.maxwords) + (' words' if params.maxwords else ' characters'),

… and the JavaScript:

// Update message
var charVerb = 'remaining'
var charNoun = 'character'
var displayNumber = remainingNumber
if (options.maxwords) {
charNoun = 'word'
}
charNoun = charNoun + ((remainingNumber === -1 || remainingNumber === 1) ? '' : 's')
charVerb = (remainingNumber < 0) ? 'too many' : 'remaining'
displayNumber = Math.abs(remainingNumber)
countMessage.innerHTML = 'You have ' + displayNumber + ' ' + charNoun + ' ' + charVerb

This means this text cannot be customised or translated (for example into Welsh) without forking the JavaScript for the component.

@matthewmascord
Copy link
Contributor

Have there been any developments on this issue recently? We need to be able to supply a version of this component with the message translated to Welsh and this is not currently possible.

@nataliecarey
Copy link
Contributor

The HMRC approach is to have language as a parameter which can be set to en or cy (for example https://design.tax.service.gov.uk/hmrc-design-patterns/open-links-in-a-new-window-or-tab/)

Being able to set the text directly would be another solution but it de-centralises the default text in Welsh.

If you need Welsh content provided I'm sure HMRC can help.

@36degrees
Copy link
Contributor Author

Hi Matthew,

Unfortunately at the minute we don't have a solution for localisation / internationalisation.

For now, we suggest that you copy the Javascript for this component into your service's codebase and make the adjustments required for the service you’re working on.

@nataliecarey
Copy link
Contributor

nataliecarey commented May 7, 2020

If we raise a PR to allow this content to be set would that be appropriate? That feels consistent with the other components.

Edit for clarity: I'm talking about the user specifying whatever content they want to replace phrases like "You can enter up to" - in our use-case we'd put in the Welsh translation

@hannalaakso hannalaakso added the awaiting triage Needs triaging by team label May 11, 2020
@hannalaakso
Copy link
Member

hannalaakso commented May 11, 2020

@natcarey We're going to need to consider internalisation/localisation as part of a wider piece of work to ensure the approach will work for all Javascript components including more complex ones in the future. This is related to #1708 and #1722.

So for now we won't be able to accept a contribution on this but thanks so much for offering to work on it, it's much appreciated 🙌 If you wanted to leave any thoughts on either of the above linked issues please feel free to do so.

@nataliecarey
Copy link
Contributor

Thanks, I'll take a look at those other issues.

@hannalaakso hannalaakso removed the awaiting triage Needs triaging by team label May 12, 2020
@RickyWelch
Copy link

Application Platform Services also have the need for this to be translatable for applications such as the SA-Filing years where a Welsh equivalent of the app is a requirement.

@simonneb
Copy link

The solution will need to be able to accurately count characters and not bytes.

The GDS Notify team recently updated their internal character counting to more accurately reflect the number of non English characters, so might be worth chatting with @quis ?

@36degrees
Copy link
Contributor Author

@simonneb there's a separate issue for that – #1104. Would you be able to add a comment there instead?

@mgladdish
Copy link

Another +1 for this. Can we get this fixed without having to wait for an entire internationalisation design review? Even just exposing a js variable with a stringformat for the message would be an improvement - then at least our apps can override the text without having to fork the entire project. It would be hacky, yes, but still better than the current situation.

@36degrees 36degrees added the awaiting triage Needs triaging by team label Aug 26, 2020
@trang-erskine trang-erskine removed the awaiting triage Needs triaging by team label Sep 7, 2020
@36degrees
Copy link
Contributor Author

Even just exposing a js variable with a stringformat for the message would be an improvement - then at least our apps can override the text without having to fork the entire project.

We do not currently have a way to pass configuration variables into a component, other than through data attributes.

Can you expand on what you mean by a stringformat? Do you have an example of what that might look like?

@mgladdish
Copy link

Actually data attributes should be fine.

If we can pass a template in as an attribute, and the js can evaluate that instead of building its own hard-coded string, then we're good.

E.g. we could pass "you have {{max}} characters remaining" as an attribute, and the js knows to pass a max arg to the template. Or even just do it with template string literals if you don't have the nunjucks engine in scope.

@girishkamat
Copy link

Hello, any progress on this issue? If not, do you recommend copying the CharacterCount code into application codebase and make the the required changes?

@hannalaakso
Copy link
Member

@girishkamat We’re currently preparing for this work but cannot unfortunately give a timeline.

For now, we suggest that you copy the Javascript for this component into your service’s codebase and make the adjustments required for the service you’re working on.

Thanks for your patience.

@domoscargin
Copy link
Contributor

Hi all,

This has been completed as part of our work on localisation and should be available in an upcoming release.

Thanks for your feedback (and patience!)

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

No branches or pull requests

10 participants