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.
Comment | File | Size | Author |
---|---|---|---|
#5 | entity-token-language-check-1987662-9738447.patch | 633 bytes | laboratory.mike |
#2 | entity-1987662.patch | 592 bytes | lee20 |
Comments
Comment #1
leanne9 CreditAttribution: leanne9 commentedI 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!
Comment #2
lee20 CreditAttribution: lee20 commentedComment #3
lee20 CreditAttribution: lee20 commentedI 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.
Comment #4
laboratory.mikeIf 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.
Comment #5
laboratory.mikeTo 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.
Comment #6
acrosmanI ran into this problem using en-uk, and the patch in #5 appears to have fixed it.
Comment #7
anushri.jain CreditAttribution: anushri.jain at TATA Consultancy Services for Pfizer, Inc. commentedWe have tested the patch with below two language code and it worked fine for us :
en-uk[British English]
gsw-berne[Swiss German]
Comment #8
rajdeepita CreditAttribution: rajdeepita at TATA Consultancy Services for Pfizer, Inc. commentedI have tested the patch for language code en-uk and gsw-berne, patch in #5 appears to have fixed it.
Comment #9
nicxvan CreditAttribution: nicxvan as a volunteer commentedWorks for simplified Chinese and Brazilian Portuguese too.
Can we get this committed to the next version?
Comment #10
fagoMaybe, 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.
Comment #11
jamesfk CreditAttribution: jamesfk at Website Express Ltd. commented+1 from me as well, just ran into this issue with a VBO for en-gb