Comments

mavimo’s picture

Status: Active » Needs review
StatusFileSize
new1.52 KB

Patch into attachment

dawehner’s picture

As you can see in #1181744: Figure out what to do update duplicate locale/language handlers there is the same handler used twice.
Perhaps first the other issue should be fixed

tim.plunkett’s picture

Triggering the testbot.

Status: Needs review » Needs work

The last submitted patch, views-language-code-1222204-1.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

Just an easy reroll.

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -26,12 +27,20 @@ class views_handler_field_node_language extends views_handler_field_node {
     $languages = views_language_list(empty($this->options['native_language']) ? 'name' : 'native');

Why not move this inside the conditional?

+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -26,12 +27,20 @@ class views_handler_field_node_language extends views_handler_field_node {
+    if (!$this->options['short_language']) {
+      $value = isset($languages[$value]) ? $languages[$value] : '';

Maybe add a comment here?

mavimo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Add @tim.plunkett suggestion

Status: Needs review » Needs work

The last submitted patch, show-node-language-code-1222204-7.patch, failed testing.

mavimo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 KB

Re-rolled patch

dawehner’s picture

dawehner’s picture

Status: Needs review » Needs work
+++ b/modules/translation/views_handler_field_node_language.incundefined
+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -14,6 +14,7 @@ class views_handler_field_node_language extends views_handler_field_node {

We should add this feature to field_locale_language as well

+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -14,6 +14,7 @@ class views_handler_field_node_language extends views_handler_field_node {
+    $options['short_language'] = array('default' => FALSE, 'bool' => TRUE);

let's name it langcode

+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -26,12 +27,22 @@ class views_handler_field_node_language extends views_handler_field_node {
+      '#description' => t('If enabled, the language will be displayed as lettercode'),

I think the proper noun for this is "langcode".

+++ b/modules/translation/views_handler_field_node_language.incundefined
@@ -26,12 +27,22 @@ class views_handler_field_node_language extends views_handler_field_node {
     return $this->render_link($value, $values);

If we return the langcode directly we should maybe sanitize the value.

mavimo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.9 KB

Patch update, with some approach change.

Into Edit language interface ( http://YOURSITE/admin/config/regional/language/edit/en ) we can see three different type of "Language display" as:

  • Language name in English
  • Native language name
  • Language code

We change the class views_handler_field_locale_language and views_handler_field_node_language to reflect this options, so user can choose from this three different options.

I think we can create a new class (views_handler_field_language) that implement this change and, to remove duplicate code, change:

  1. handler into /modules/locale.views.inc to use a unique class (views_handler_field_language)
  2. parent class into /modules/locale/views_handler_field_node_language.inc and /modules/locale/views_handler_field_locale_language.inc

Let me know what do you think about this change.

dawehner’s picture

Status: Needs review » Needs work
+++ b/modules/locale/views_handler_field_locale_language.incundefined
@@ -13,24 +13,37 @@
+    if ($this->options['language_display'] == 'langcode') {

When you rename options, you should at least take care that the options are converted in the init method unless you want to break existing sites :)

mavimo’s picture

Status: Needs work » Needs review
StatusFileSize
new4.67 KB

@dawehner Done

lolandese’s picture

Status: Needs review » Reviewed & tested by the community

Particularly nice that an empty language field results in the code 'und'.

Needed this functionality to create e CSV export file with the "Content: Language" field. To validate when mapped with an importer using the Feeds module. For anyone having the same particular problem and tied to the use of the stable version of Views, have a look at http://drupal.org/node/1819720, using the Feeds Tamper module.

mxt’s picture

I need this feature too: for now I have to use this workaround:

  1. Install views_php module
  2. Add a php field to your views
  3. Put this code inside the php field:
<?php
global $language;
print $language->language; 
?>

Hope this patch will be committed soon

skyredwang’s picture

also tested, and the #14 patch works!

playfulwolf’s picture

applied the patch, but do not understand what it supposed to do?

yang_yi_cn’s picture

it provides an option in the views field to allow display language in formats other than the human readable name (machine code, for example).

I'm using it but there are some bugs when you try to edit an existing view, as the existing view don't have that variable saved so it throw an invalid index PHP error.

Also I experienced AJAX/PHP error when you try to use it on a non-Node view. It's because in file views_handler_field_locale_language you cannot render_link(). That is a function for node handler only, you can only return the text value.

I'm attaching the updated patch here (rolled against Views-7.x-3.7

yang_yi_cn’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.9 KB

I'm attaching the updated patch here (rolled against Views-7.x-3.7

Status: Needs review » Needs work

The last submitted patch, 20: views-show-node-language-code-1222204.fixed_.patch, failed testing.

dagmar’s picture

StatusFileSize
new4.89 KB

Re-rolled using git

dagmar’s picture

Status: Needs work » Needs review
graker’s picture

The patch from #22 works for me. The only thing I had to do is to delete the Language field from my view and then to add it again so the field display option becomes available.
Thanks!

skyredwang’s picture

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

Hi,
is this currently implemented in a stable version?

I am using 7.x-3.7 and can't find this option. How can I obtain the language code?

Thanks
Rainer

damienmckenna’s picture

Assigned: mavimo » Unassigned

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: views.1222204-22.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: views.1222204-22.patch, failed testing.

shaxa’s picture

Patch is not working correctly since it always unsets the new option if you are applying it for the first time and you have the native option set. I am applying a new working patch.

shaxa’s picture

Status: Needs work » Needs review
asiby’s picture

I gave it another try. The following patch show work. I have also successfully did the same thing using hooks. That can be useful if you (just like myself) badly need this patch before it is approved and merged.

asiby’s picture

asiby’s picture

asiby’s picture

Sorry guys. I got confused by the way the reply IDs are provided and the timing of how I should number my patch. Here is the same patch again... but this time, with the number 37.

zalak.addweb’s picture

Issue tags: +views
nitesh sethia’s picture

Version: 7.x-3.x-dev » 7.x-3.20
Issue tags: -views +PatchingTime
StatusFileSize
new4.83 KB

Updating the patch with some commenting.

damienmckenna’s picture

Version: 7.x-3.20 » 7.x-3.x-dev
Status: Needs review » Needs work

Am concerned that changing the form fields would break existing Views definitions, so adding an update script or allowing it to also support the previous value might be a good idea.

jenlampton’s picture

Issue tags: -

For those who need langcode in a view, see https://www.drupal.org/project/views_language.