Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Currently i have two javascripts:

JavaScript
(function ($) {
    $(".video-toggle").on("click", function () {
        let $btn = $(this);
        let $video = $("#video-" + $btn.attr("data-id"));
        if ($btn.text() == "Video ansehen") {
            $btn.text("Video verstecken");
            loadVideo($video);
            $video.show(0);
        } else {
            $btn.text("Video ansehen");
            $video.hide(0);
        }
    });

    function loadVideo($video) {
        let $iframe = $video.find("iframe");
        if (!$iframe.is('[src]')) {
            $iframe.attr("src", $iframe.attr("data-src"));
        }
    }

    $(document).ready(function () {
        let $video = $(".video-container");
        if ($video.hasClass("auto-load")) loadVideo($video);
    });
})(jQuery);
and
JavaScript
(function ($) {
    $(".video-toggle").on("click", function () {
        let $btn = $(this);
        let $video = $("#video-" + $btn.attr("data-id"));
        if ($btn.text() == "Show Video") {
            $btn.text("Hide Video");
            loadVideo($video);
            $video.show(0);
        } else {
            $btn.text("Show Video");
            $video.hide(0);
        }
    });

    function loadVideo($video) {
        let $iframe = $video.find("iframe");
        if (!$iframe.is('[src]')) {
            $iframe.attr("src", $iframe.attr("data-src"));
        }
    }

    $(document).ready(function () {
        let $video = $(".video-container");
        if ($video.hasClass("auto-load")) loadVideo($video);
    });
})(jQuery);


Depending on the CurrentCulture it loads one of these scripts. The most of the code are the same.

Is it possible to use just one script?

What I have tried:

I googled about it, but found just examples for localizing html with javascript.
Posted
Comments
0x01AA 28-Dec-22 7:07am    
The first step will be to refactor the code where decisions will be taken on e.g. button captions.
After that you simply can localize the GUI elements while loading the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900