Git Product home page Git Product logo

Comments (8)

SahAssar avatar SahAssar commented on August 23, 2024

@zomars: Would this be for the backend one, the frontend one or both? (as in the general idea, not the specific twig code)

from translate.

zomars avatar zomars commented on August 23, 2024

My solution is for the frontend only, but maybe it could be implementing according to the number of the configured languages. Mine's just a quick fix.

from translate.

madc avatar madc commented on August 23, 2024

First, thanks for sharing your snippet. The way, I see it, the _localeswitcher.twig, that is included with the extension, is just demonstrating how to implement such functionality. The template of the twif function can easily be overwritten. Also, the ul from the default template can be styled with CSS, so it will look exactly like yours.

from translate.

SahAssar avatar SahAssar commented on August 23, 2024

In addition to what @madc said it is also planned to have proper language codes (as rel="alternate" and hreflang="lang-here") for each link in both the localeswitcher and to add them to <head> (automatically that is), IIRC it helps search engines and accessibility to have a link that is "active"/"current" when doing that. Adding .localeswitcher .active {display: none;} should remove that element from display while allowing you style the rest as needed, or want to you can remove it completely using a custom template.

If I'm wrong on the accessibility front (requiring a "current" link) I think we could probably remove it though.

And also thank you for raising the issue!

from translate.

madc avatar madc commented on August 23, 2024

One thing, that didn't leave my head since we talked about this other issue (#36):

It would make the localeswitcher way simpler, if we would move all this url business into the php code of the twig function and just inject a clean array of objects into the template.

So from the current template we should be able to have something like:

<ul class="localeswitcher {{ extraclasses }}">
    {% for iso, locale in locales %}
        <li {% if locale.active %}class="active"{% endif %}>
            <a title="{{ locale.label }}" href="{{ locale.url }}">
                {{ locale.label }}
            </a>
    {% endfor %}
</ul>

The object could look something like this:

[
   en_GB: {
       slug: en,
       active: true,
       label: English,
       url: http://whatever/en
   },
   de_AT: {
       slug: de,
       label: German,
       url: http://whatever/de
   },
   [...]
]

from translate.

SahAssar avatar SahAssar commented on August 23, 2024

@madc Yep, that's the plan... That part of the code is basically copy-pasted verbatim from the 2.2 version, so it hasn't gotten as much love as the rest. I also planned to make it available as a global in twig so that one could just loop and output it wherever without having to make a specific template for that part...

from translate.

madc avatar madc commented on August 23, 2024

That a good idea. I'd have a look at it, if you don't mid..

from translate.

SahAssar avatar SahAssar commented on August 23, 2024

Sounds great! Then we could get rid of the ugly getSlugFromLocale function too, which hasn't seen any work in a while either.

from translate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.