The default text "Select Some Options" or "Select an Option" should be translatable at least. And if not even configurable. I temporarily hacked my Chosen library to make use of the Drupal.t() javascript function. But I'm sure the module could easily replace the text with a configurable variable...

I'm interested in your thoughts on this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ddorian’s picture

Also Interested

Cyclodex’s picture

Just came over this too.
There is also more text which should be translatable: Noting down the ones which we should try to fix:

  • "Select an Option"
  • "Select Some Options"
  • "No results match"

Short investigation showed me that "No results match" is a option, so I will add this to my other already implemented options.
But I think I should not call it then as t(), perhaps we need this as translatable variable, not yet sure how to do this. (give me some time)

The other too needs some jquery change. I will try to have a look on that and will post you a patch here later.

Cheers Cyclodex

shadcn’s picture

Status: Needs review » Needs work

Chosen picks the placeholder from a data attributes. As a temp solution, a form alter and adding this attributes can help.

$form['some_field']['#attributes']['data-placeholder'] = t('Choose an option');
mh86’s picture

Status: Active » Needs review

This can be easily fixed with adding following line to the chosen.js file:

options.placeholder_text = Drupal.t('Select Some Options');
bago’s picture

Status: Needs work » Needs review
FileSize
590 bytes

Here is a patch. It works only against recent chosen.js libraries (>= june 2012).
I preferred to localize the "extended" versions:
+ options.placeholder_text_multiple = Drupal.t('Choose some options');
+ options.placeholder_text_single = Drupal.t('Choose an option');

bago’s picture

FileSize
703 bytes

This one also supports "No results match" localization.
Please note that the string will appear as "No result match" followed by the text searched, so this will have to be taken into account during translation.

Cyclodex’s picture

Thanks for the diff's and the feedback, works for me too.
Looks like we can implement this that way

bago’s picture

Status: Needs review » Reviewed & tested by the community
Cyclodex’s picture

Assigned: Unassigned » Cyclodex
Cyclodex’s picture

Status: Reviewed & tested by the community » Fixed

I just commited this into the dev! Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jmuzz’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
Status: Closed (fixed) » Needs review
FileSize
1.44 KB

It looks like this solution was removed in the latest version, at least for customized strings. I saw that they were being loaded from variables but they weren't appearing in the Translatable Variables module. This patch adds a chosen.variables.inc file to allow these 3 strings to be translated with Translatable Variables.

Hydra’s picture

Title: Default select text should be translatable » Variables should be implemented using hook_variable_info for proper translation

Closed #2087683: Implement Variable API to allow for translation of text variables as a duplicate, since the solution is the same.
Unfortunally I had no time to test this properly, I would love to see this in chosen before stable release, since so many people have issues with translating variables

lmeurs’s picture

#12 works great, many thanks!

boyan.borisov’s picture

Issue summary: View changes

#12 works for me, too.

boyan.borisov’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 5: chosen-1591908.diff, failed testing.

The last submitted patch, 6: chosen-1591908-bis.diff, failed testing.

Dave Reid’s picture

Title: Variables should be implemented using hook_variable_info for proper translation » Add Variable module integration (via hook_variable_info)
Category: Task » Feature request
Priority: Major » Normal
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
  1. +++ b/chosen.variable.inc
    @@ -0,0 +1,53 @@
    +function chosen_variable_info($options) {
    +  $variables['chosen_placeholder_text_multiple'] = array(
    

    This hook doesn't seem to define all the variables used by Chosen? Why?

  2. +++ b/chosen.variable.inc
    @@ -0,0 +1,53 @@
    +    );
    

    Closing paren for arrays should be unindented here as per coding standards.

  3. +++ b/chosen.variable.inc
    @@ -0,0 +1,53 @@
    +    );
    

    Same

  4. +++ b/chosen.variable.inc
    @@ -0,0 +1,53 @@
    +    );
    

    Same

  5. +++ b/chosen.variable.inc
    @@ -0,0 +1,53 @@
    + ¶
    

    Adds an extra space at the end of the line here which should be removed.

pcambra’s picture

Status: Needs work » Needs review
FileSize
1.43 KB

Hi Dave,

I don't think we need to expose all chosen variables because the main intent of this patch is making them translatable, excepting the strings displayed (these are exposed to variable with this patch), the rest of variables are settings that doesn't make a lot of sense to translate.

Here's a new patch taking care of the coding standards bit.

lmeurs’s picture

Status: Needs review » Reviewed & tested by the community

Patch is (besides coding standards corrections) the same as the earlier RTBC patch. Successfully re-applied this version of the patch to Chosen 7.x-2.0-beta4, thanks a lot!

  • jmuzz authored e7a0d22 on 7.x-2.x
    Issue #1591908 by bago, pcambra, jmuzz | alexverb: Added Variable module...
Hydra’s picture

Status: Reviewed & tested by the community » Fixed

Looks good to me, Thx @all! committed to 7.x-2.x http://cgit.drupalcode.org/chosen/commit/?id=e7a0d22

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kopeboy’s picture

Version: 7.x-2.x-dev » 7.x-2.0-beta4
Status: Closed (fixed) » Needs review

Is this included in beta?

I can see the strings at admin/config/regional/translate/translate but once translated they are not showing up, still only english is present.

hass’s picture

Version: 7.x-2.0-beta4 » 7.x-2.x-dev
Status: Needs review » Closed (fixed)
hansrossel’s picture

@kopeboy: need to enable variable module and then check the chosen variables first at admin/config/regional/i18n/variable