English does not show up when activated

#1

I have a simple language switch, copied from here. When im on the homepage and switch from german to english, english is not shown anymore. The homepage is translated and the file has all needed permissions.

The strangest thing: I have two switches for the language (I know its bad, but the design is made like that) and the second language switch works (meaning even when english is selected, it gets marked as “active” and is still showing up).

However there is no difference between them as they use the same snippet and when I remove the first language switch so there is just one, this one will also remove the english li element when i switch to english. PS: No Dom manipulation is happening, so i guess it’s a problem within php.

Here is my language switch snippet:

<nav class="languages hide--<?= $view ?>" id="languages">
  <ul>
    <?php foreach($kirby->languages() as $language): ?>
      <li class="<?php e($kirby->language() == $language, 'active') ?>">
        <a href="<?= $page->url($language->code()) ?>"><?= html($language->name()) ?></a>
      </li>
    <?php endforeach ?>
  </ul>
</nav>
0 Likes

#2

Is the li really missing in the source? What does the hide--<?= $view ?> styling do?

0 Likes

#3

the hide-- class hides the hole navigation depending on mobile or desktop environment. As i said, its nothing too beautiful.

Yes, the english <li> element is completely gone in the source. It’s not just hidden by any display:none code, it’s not shown in the DOM at all, when i look at it with the dev console.

0 Likes

#4

Is the site online? I’d say it has nothing to do with the PHP code, but sounds more like a JS thingy.

0 Likes

#5

Yes, Here you’ll find (link removed) a test where stripped out all other stuff (no JS in here as you see).

0 Likes

#6

What does your language configuration look like? And what is the Kirby version you are using?

0 Likes

#7

It’s Kirby Version 3.1.1, i think it’s the newest, right? Before this update, it didn’t work as well, though.

config.php:

<?php
return [
    'debug' => true,
    'languages' => true,
    'languages.detect' => false,
    'markdown' => [
      'extra' => true
    ]
];

de.php:

<?php

return array (
  'code' => 'de',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => '/',
);

en.php:

<?php

return array (
  'code' => 'en',
  'default' => false,
  'direction' => 'ltr',
  'locale' => 'en_US',
  'name' => 'English',
  'url' => 'en'
);

(/en didn’t work as well)

0 Likes

#8

The latest release is 3.1.2, so maybe you could update first and then test again.

Some the second language doesn’t seem to be recognized.

What happens if you do a

dump($kirby->languages());

Your URL for English should definitely be /en with the slash.

0 Likes

#9

Updated to 3.1.2, changed to “/en” again, nothing changes.

dump($kirby->languages());

gives an interesting output thought - even when changing to english and just the english li
element is shown, this gives:

Kirby\Cms\Languages Object
(
    [0] => de
    [1] => en
)
0 Likes

#10

Ok, stripped out every php output, and this is the problem here, what removes the english entry when changing to english:

<?= $page->url($language->code()) ?>
0 Likes

#11

I just tested this again with a fresh Starterkit and still can’t reproduce your issue.

Have you verified this with a fresh Starterkit?

0 Likes

#12

I played a lot arround and noticed that the problem occurs on my side, when you delete the following line in the starterkit from the header.php:

<?= css(['assets/css/index.css', '@auto']) ?>
0 Likes

#13

That sounds even more weird, because all that line does is add the stylesheet. If I remove that line, my language switcher is still there but no styles.

0 Likes

#14

Yeah it’s very strange to me as well… So what i am doing:

  1. Unpack starter kit
  2. add the following files to site/languages/:
    de.php:
<?php

return [
  'code' => 'de',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => '/',
];

en.php:

<?php

return [
  'code' => 'en',
  'default' => false,
  'direction' => 'ltr',
  'locale' => 'en_US',
  'name' => 'English',
  'url' => '/en'
];
  1. Add the following lines to the header.php snippet, right under the body tag:
...
<body>
  <nav class="languages" id="languages">
    <ul>
      <?php foreach($kirby->languages() as $language): ?>
        <li class="<?php e($kirby->language() == $language, 'active') ?>">
          <a href="<?= $page->url($language->code()) ?>"><?= html($language->name()) ?></a>
        </li>
      <?php endforeach ?>
    </ul>
  </nav>

  <div class="page">
...
  1. Remove this line from header.php:
<?= css(['assets/css/index.css']) ?>

PS: Using LAMP stack.
PPS: This problem happens on the /home page and the starter example /photography page, at the subpage /photography/animals it works actually.

0 Likes

#15

If you add your languages manually like that (instead of through the Panel), the text files in your content folder are not modified with the language extension. Maybe that’s the problem?

1 Like

#16

Nope. The problem occurs both when I remove these files from my existing project and add them by admin panel and when I start over again from starter kit and add languages by admin panel… :frowning:

0 Likes

#17

Sounds as if there’s something wrong with your configuration. As I said I can’t for the life of me reproduce this.

0 Likes

#18

Can you reproduce it using this (link removed) kirby installation?

0 Likes

#19

Yes, and I also found that it happens when the language switch is located like in your test before the navigation while it doesn’t happen with the language switch located after the navigation where I put it in my test.

But I have no idea what’s happening here.

0 Likes

#20

Okay, I’m happy that it’s not because im too stupid to make the configurations… :wink:
So… will we treat that as a bug? As i said, besides the navigation, the css() function also seems to fix that, when it’s before the languages foreach loop…

0 Likes