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

Internalisation feature #9

Open
jgoux opened this issue Dec 10, 2013 · 8 comments
Open

Internalisation feature #9

jgoux opened this issue Dec 10, 2013 · 8 comments

Comments

@jgoux
Copy link

jgoux commented Dec 10, 2013

I think it would be a good idea to add internalisation to dynatable.
At the moment we can only overwrite some words in the inputs:{} default configuration object.
Maybe we could use some sentences to parse like :
inputs: {
recordCountText: 'Showing {x} to {y} of {z} records'
}

@JangoSteve
Copy link
Member

I agree it would be ideal to allow just passing in a template string (e.g. using the Smarty template syntax as in your example and as in how the docs explain it). The one reason I would be hesitant is that we then have to build the ability for dynatable to parse out the template (short of writing or requiring the template engine itself into dynatable).

I think as a short-term solution, we should just add config options for each part of the the record-count text, so that dynatable can continue just using string concatenation to put the whole thing together. Something like this:

inputs: {
  recordCountTextShowing: 'Showing ',
  recordCountTextTo: ' to ',
  recordCountTextOf: ' of ',
  recordCountTextFilteredStart: ' (filtered from ',
  recordCountTextFilteredEnd: ' total records)' 
}

Such that the entire string would be concatenated as:

# if no query/filter applied
{dataset.recordCountTextShowing} {x} {inputs.recordCountTextTo} {y} {inputs.recordCountTextOf} {z} {params.records}

# if query/filter applied
{dataset.recordCountTextShowing} {x} {inputs.recordCountTextTo} {y} {inputs.recordCountTextOf} {z} {params.records} {recordCountTextFilteredStart} {n} {recordCountTextFilteredEnd}

as opposed to how it's currently concatenated, which has most of the text hard-coded:

# if no query/filter applied
{dataset.recordCountText} {x} to {y} of {z} {params.records}

# if query/filter applied
{dataset.recordCountText} {x} to {y} of {z} {params.records} (filtered from {n} total records)

@JangoSteve
Copy link
Member

Actually, looking a bit further into it, I think we probably could build a very basic template function that's fast and efficient for what we need. Maybe something along the lines of this StackOverflow post, but changing up the regex to use our more smarty-like syntax (which I prefer).

@jgoux
Copy link
Author

jgoux commented Dec 10, 2013

The regex looks like the perfect solution.
I think we could extend the templating to all the elements of the table including the search input. For example with bootstrap I like the input groups feature which allows me to add a magnifier icon in my search input. (http://getbootstrap.com/components/#input-groups-basic)

@brandondrew
Copy link

Internalisation? I assume you mean Internationalization? (Or internationalisation, to give a localized version :) .)

@jgoux
Copy link
Author

jgoux commented Dec 16, 2013

Yes I wanted to say internationalization sorry !
Thanks for correcting me.

@brandondrew
Copy link

No problem. I didn't mean to be correcting so much as clarifying.

@JangoSteve
Copy link
Member

I've now added full customization to the record-count text. The new configuration options with defaults are:

inputs: {
    recordCountPageBoundTemplate: '{pageLowerBound} to {pageUpperBound} of',
    recordCountPageUnboundedTemplate: '{recordsShown} of',
    recordCountTotalTemplate: '{recordsQueryCount} {collectionName}',
    recordCountFilteredTemplate: ' (filtered from {recordsTotal} total records)',
    recordCountText: 'Showing',
    recordCountTextTemplate: '{text} {pageTemplate} {totalTemplate} {filteredTemplate}'
}

The main option above is recordCountTextTemplate, which essentially just concatenates the other sub-templates. The record-count text had to be broken into the sub-templates, because it loads different parts depending on different scenarios for the current state of the data (including page and active queries).

You can define your own templates using any of the variables above, which correspond to:

text:settings.inputs.recordCountText
pageTemplate:settings.inputs.recordCountPageBoundTemplate if the table is paginated, or settings.inputs.recordCountPageUnboundedTemplate if the table is paginated but all of the records are shown on the current page (e.g. if the number of records per-page is greater than the number of total records, or if the results are being filtered and the number of filtered records is less than the number of records per-page), or empty string if pagination is disabled.
totalTemplate:settings.inputs.recordCountTotalTemplate
filteredTemplate:settings.inputs.recordCountFilteredTemplate if search or queries are enabled and there is 1 or more queries currently applied to the data, or empty string if not.
recordsTotal:settings.dataset.totalRecordCount
recordsShown:records.count()
recordsQueryCount:settings.dataset.queryRecordCount
collectionName:settings.params.records
pageLowerBound:The first record shown on the current page, otherwise undefined
pageLowerBound:The last record shown on the current page if pagination enabled, otherwise undefined

@lusabo
Copy link

lusabo commented Feb 19, 2015

Hi @JangoSteve ,

I'm trying to translate the Dynatable to Portuguese as your explanation above, but I'm not getting it.

...
params : {
    records : "registros"
},
inputs : {
    recordCountPageBoundTemplate : '{pageLowerBound} a {pageUpperBound} de',
    recordCountPageUnboundedTemplate : '{recordsShown} de',
    recordCountText : 'Mostrando ',
    recordCountTextTemplate : '{text} {pageTemplate}'
}
...

I took a look at the source code and I think the problem is between the lines 707 and 737.
Words like to and of are fixed of the code, so I'm unable to internationalize.

Similar to pageLinks += '

  • Pages:
  • '; at line 1342. How change the label Pages:?

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

    No branches or pull requests

    4 participants