I'm developing a multilingual site. One of the languages used on the site includes a hyphen in its code (Swiss German, code gsw-berne). If I open the Content page, select some multilingual node(s) and use the "Change Value" operation to change Language to Swiss German, it fails with the error message "Language contains an invalid value".

This happens because the entity_metadata_node_entity_property_info function says the language property is of type token, and entity_property_verify_data_type validates that type using a regexp that does not consider a hyphen as a valid character. I think it should be considered valid, as token is advertised as a good choice for machine names, and the machine name for the default main menu includes a hyphen.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

leanne9’s picture

I am also having this issue. I appreciate that sarunas has provided some clarity as to why it is happening, any ideas on what to do to fix? Thanks!

lee20’s picture

Issue summary: View changes
FileSize
592 bytes
lee20’s picture

I attached a patch that solves the issue for me. It's a pretty simple change to the regex that allows hyphens. But I am not sure if this will allow things to validate that shouldn't validate for other use cases.

laboratory.mike’s picture

Status: Active » Needs review

If there is a concern about validating dashes in other contexts, we can also use field_valid_language(). The function works by checking whether a language is valid, and if it is, it returns it. If not, it returns a default language. I will write up this case in a patch; we would wrap the regex in an OR statement if we need to avoid dashes.

laboratory.mike’s picture

To see what's being passed, throw in a dpm() for $data and $type, and try changing a language via VBO or a function that needs to validate a language token.

acrosman’s picture

I ran into this problem using en-uk, and the patch in #5 appears to have fixed it.

anushri.jain’s picture

Status: Needs review » Reviewed & tested by the community

We have tested the patch with below two language code and it worked fine for us :
en-uk[British English]
gsw-berne[Swiss German]

rajdeepita’s picture

I have tested the patch for language code en-uk and gsw-berne, patch in #5 appears to have fixed it.

nicxvan’s picture

Works for simplified Chinese and Brazilian Portuguese too.

Can we get this committed to the next version?

fago’s picture

Status: Reviewed & tested by the community » Needs work

Maybe, but token has been specificed otherwise. If languages do not comply with the token spec, the data type of language codes need to be changed - not the token spec.

jamesfk’s picture

+1 from me as well, just ran into this issue with a VBO for en-gb