-
Notifications
You must be signed in to change notification settings - Fork 158
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
feat: translations #145
feat: translations #145
Conversation
@hrwX can you add an example how this can be used? How do I get my custom labels to use the original actions? Lines 9 to 33 in 699ef5d
|
|
@hrwX thanks for adding the example, looks good to me. @netchampfaris what do you think? |
I think a better API for translations would be: let dt = new DataTable({
...
translations: {
'Sort Ascending': __('Sort Ascending'),
'Sort Descending': __('Sort Descending'),
}
}) You provide alternative text for every user-facing text that is rendered in DataTable. @hrwX @barredterra Thoughts? |
699ef5d
to
2e19559
Compare
@netchampfaris thanks for your suggestion! Kindly review again whenever you have time. 😊 |
@hrwX Hey, thanks for the quick update. However, I think we should extend this for every user-facing text in DataTable. For e.g., "No Data" when there are no rows. Every user-facing text must be wrapped in a function that will then look up translations strings passed as options. This will make sure that user-facing text added in the future are also covered. |
src/datatable.js
Outdated
setTranslations() { | ||
if (!this.options.translations) return; | ||
|
||
this.options.headerDropdown.forEach(header => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method only handles translations for labels in headerDropdown, it should handle all user-facing text. A better approach would be to wrap all user-facing text in a translation function for e.g., _('Sort descending')
and let that function do the replacement.
@netchampfaris @hrwX if we pass a function, we also need to pass variables and context to that function. This way datatable and frappes Another option would be to use something like http://i18njs.com/ and provide our own translations in this repo to keep it as a standalone solution. There are <10 translatable strings in this repo, so this would't cause much overhead. |
@netchampfaris Correct me if I am wrong |
2e19559
to
770b8ee
Compare
61660a2
to
0b09d6c
Compare
@netchampfaris @barredterra have added i18njs for handling the translations for user-facing strings. |
Yes, this is what I meant. I would like to avoid adding a new library 😅 |
@netchampfaris those libraries are tiny (~200 lines of code). If you prefer we can just copy and paste the code here. |
0b09d6c
to
055b726
Compare
@barredterra @netchampfaris Was able to implement a translation manager similar to the ones in frappe. Also after implementing frappe like translations, seems like i18njs would have been a bloatware since we would just use it for 4/5 strings. what do you guys think ? |
9ceb0b2
to
3e472c2
Compare
src/translationmanager.js
Outdated
'No Data': 'No Data', | ||
'{0} {1} copied': '{0} {1} copied', | ||
'{0} {1} selected': '{0} {1} selected' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de: {
'Sort Ascending': 'Aufsteigend sortieren',
'Sort Descending': 'Absteigend sortieren',
'Reset sorting': 'Sortierung zurücksetzen',
'Remove column': 'Spalte entfernen',
'No Data': 'Keine Daten',
'{0} cells copied': {
0: '{0} zellen kopiert',
1: '{0} zelle kopiert',
default: '{0} zellen kopiert'
},
'{0} rows selected': {
0: '{0} zeilen ausgewählt',
1: '{0} zeile ausgewählt',
default: '{0} zeilen ausgewählt'
}
}
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
2b17471
to
c91610d
Compare
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
* Create fr.json * feat: italian translations * feat: add "fr" and "it" to getTranslationsJSON
🎉 This PR is included in version 1.16.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
customTranslations
when initializing the datatable.row/rows
, multiple strings can be defined for counts, ie for a particular count, if a string is defined, it'll be used. eg: if the total row count is 0, the string for key 0 will be using in{0} rows selected
the translations and if there exists no key like 10, default key will be used for translation. This way multiple use cases can be handled