As a user, I would like to see the language drop-down only for the available translations.

Some sites only have few translated pages, adding a language switch will give them a false promise.

Its, good to add another checkbox in block settings to say "Display only available translations". So, if there no translations, other than default language hide the block

Comments

Rookie Rodrigo created an issue. See original summary.

stephenrodrigo@yahoo.com’s picture

I just found out that there is a checkbox called 'Show all enabled languages'.
I have created a patch to select all languages if that box is ticked and select an available language if it's not ticked.

stephenrodrigo@yahoo.com’s picture

StatusFileSize
new1.58 KB
stephenrodrigo@yahoo.com’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 2920119-display-available-translate-language.patch, failed testing. View results

bserem’s picture

The patch does not apply against latest dev.

bserem’s picture

StatusFileSize
new1.66 KB

Rerolling patch against latest dev

bserem’s picture

Status: Needs work » Needs review

The last submitted patch, 3: 2920119-display-available-translate-language.patch, failed testing. View results

kala4ek’s picture

Assigned: stephenrodrigo@yahoo.com » Unassigned
Status: Needs review » Needs work

Patch needs to be updated. At least direct using of \Drupal::routeMatch() should be replaced by DI of necessary container.

prashant.c’s picture

Status: Needs work » Needs review
StatusFileSize
new3.48 KB
new2.4 KB

Changed \Drupal::routeMatch() with Dependency Injection.

kala4ek’s picture

Status: Needs review » Needs work

@Prashant.c you did not run and check your code, right? ;)
At least the number of arguments received in __constract and arguments passed in create does not match.

prashant.c’s picture

Status: Needs work » Needs review
StatusFileSize
new4.09 KB
new1.73 KB

@kala4ek

Sorry i could not test it.

Submitting again with changes please review is it good now ?

prashant.c’s picture

Any updates on this , any reviews?

kala4ek’s picture

Assigned: Unassigned » kala4ek
_dcre_’s picture

There is an issue with the patches. Its more of an issue of ContentEntityBase::getTranslationStatus
Im not sure if this an actual bug of getTranslationStatus or just a misconception from my side.
The fact of the matter is that getTranslationStatus returns 1 if a translation exists but is unpublished.
In this case, you get to see that language in your lang switcher although the actual translation cannot be accessed.

The attached patch tries to correct this behaviour.

Status: Needs review » Needs work
_dcre_’s picture

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

Fixed patch is attached

Status: Needs review » Needs work
_dcre_’s picture

hopefully this time i will get it right

scotwith1t’s picture

Why target just nodes? What about other translatable entity types (e.g., Group entities from Group module)?

t_d_d’s picture

Since i needed this and Dropdown Language module has this built in already, i just used relevant piece of code. So far its working.

Im noob when it gets to posting patches to issues and all that stuff with git (https://www.drupal.org/node/707484 - my head will explode, its to complicated). I just created patch, will attach it to this issue, hope i will help someone and hope that i wont break something badly...

johnpicozzi’s picture

The last patch seems to work well at limiting the list of languages. However, It doesn't hide the block if only one language is present.

pianomansam’s picture

@johnpicozzi here is a new patch that adds a configuration option to hide if only one language is available.

pianomansam’s picture

StatusFileSize
new4 KB

The previous patch doesn't apply to 2.x-dev anymore plus it had a bug that didn't correctly set the cache context. Here's a new patch that applies to dev and fixes the cache context issue.

pianomansam’s picture

Let's try that patch again.

Status: Needs review » Needs work
pianomansam’s picture

Status: Needs work » Needs review
StatusFileSize
new5.48 KB

Here's yet another iteration on this patch. Because the cache context was only being applied to the route, adding or changing the translations for a node didn't clear the block cache for the node so the block wouldn't show up without a full cache clear. Additionally, the code from earlier patches only considered the first entity in the current Drupal route. I rewrote that section to consider all entities.

Oh, and I added this missing schema so hopefully the tests will fire.

Status: Needs review » Needs work

The last submitted patch, 28: lang_dropdown-display_available-8.x-2.x-dev-2920119-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pianomansam’s picture

Status: Needs work » Needs review
StatusFileSize
new6.55 KB

Tests still assumed the default was to show all languages. Hopefully this update fixes them.

pianomansam’s picture

Title: Display language switch block if translation available. » Only display language switch block if translation available
StatusFileSize
new6.51 KB

Cache wasn't always clearing when adding translations, probably due to not properly using $entity->getCacheTags()

pianomansam’s picture

Status: Needs review » Needs work

I'm still getting reports that the cache is not correctly clearing.

pianomansam’s picture

Status: Needs work » Needs review
StatusFileSize
new6.72 KB

Here's another pass at this, hopefully with caching fixed.

  • kala4ek committed c889f02 on 8.x-2.x authored by pianomansam
    Issue #2920119 by pianomansam, _dcre_, Prashant.c, stephenrodrigo@yahoo....
kala4ek’s picture

Assigned: kala4ek » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

google01’s picture

In configurations with visibility management by roles, version 4.0 that includes this patch does not work correctly.

Unfortunately it hides the languages of the translations in the dropdown.

This issue is not repeated in version 2.0-beta4.