Sign in

Having Trouble Adding Custom JavaScript to Post | Website Translation Attempt

  • This topic has 9 replies, 3 voices, and was last updated 1 year, 11 months ago by .
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #5984
    Avatar photocandidexmedia

    Hello!

    I’ve been toying around with Publii for a while now and I’m looking for ways to get around making the website multilingual / multi-language. I found this simple Javascript-based localization library called Lingumania that seems to be simple enough to implement for what I need.

    I included a link to the lingumania.min.js script src in Tools > Custom HTML > Body (step 2 from their website) that I’ve hosted online.

    I then created a post, clicked on “Source Code – HTML”, and copy-pasted the following code from their website from their first demo:

    <h1>Ready to go global?</h1>
        <h2>get found by search engines and visitors in other languages</h2>
        Powered by Lingumania
        <script type="text/javascript">
            var linguJSON = {
                "languages": [
                    {
                        "lang_name": "English",
                        "lang_code": "en",
                        "url_pattern": "?"
                    },
                    {
                        "lang_name": "Español",
                        "lang_code": "es",
                        "url_pattern": "?"
                    }
                ],
                "translated_segments": [
                    {
                        "source": "Ready to go global?",
                        "target": "¿Está listo para el mundo?"
                    },
                    {
                        "source": "get found by search engines and visitors in other languages",
                        "target": "sea encontrado por los motores de búsqueda en otros idiomas",
                    },
                    {
                        "source": "Powered by Lingumania",
                        "target": "Potenciado por Lingumania"
                    }
                ]
            };
        </script>
        <script src="js/lingumania.min.js">

     

    However, the translation toggle button doesn’t show up. Here is how the mechanism should work: http://www.lingumania.com/Demos/QuickDemo.html

    Any idea how to solve this?

     

    #5989
    Avatar photoTomasz Dziuda

    Hi,

    If the scripts correctly appears in your theme, then you must consult the issue with the author of the library – it is the best source of the issue solutions in such cases 🙂

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #5992
    Avatar photocandidexmedia

    Hi,

    If the scripts correctly appears in your theme, then you must consult the issue with the author of the library – it is the best source of the issue solutions in such cases 🙂

    Hi Tomasz! How do I know if the scripts appear in my theme?

    #5993
    Avatar photoTomasz Dziuda

    Please just open your website and view source – https://neilpatel.com/blog/how-to-read-source-code/

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #5996
    Avatar photocandidexmedia

    So, it looks like my replies keep getting deleted, but I checked the source, and it looks like the script is present in the head of the page source. That said, I’ve run into issues with trying to add Custom HTML with .js scripts for other web components/Javascript libraries.

     

    I tried adding the Able Player to a new Publii site using the QF template and testing the player out, but also ran into some issues.

    Here is the code I added to the Head (via Tools > Custom HTML > Head):

    <!-- Dependencies -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        
    <script src="https://ableplayer.github.io/ableplayer/thirdparty/js.cookie.js"></script>
    
    <!-- CSS -->
    <link rel="stylesheet" href="https://ableplayer.github.io/ableplayer/build/ableplayer.min.css" type="text/css"/>
    
    <!-- JavaScript -->
    <script src="https://ableplayer.github.io/ableplayer/build/ableplayer.js"></script>
    #5997
    Avatar photocandidexmedia

    In a new post using the WYSIWYG editor, I clicked on “HTML” and pasted the following:

    <video id="video1" poster="https://ableplayer.github.io/ableplayer/media/wwa.jpg" preload="auto" width="480" height="360" data-able-player="" data-skin="2020">
      <source type="video/mp4" src="https://ableplayer.github.io/ableplayer/media/wwa.mp4" />
      <source type="video/webm" src="https://ableplayer.github.io/ableplayer/media/wwa.webm" />
      <track kind="captions" src="https://ableplayer.github.io/ableplayer/media/wwa_captions_en.vtt" srclang="en" label="English captions" /></video>

     

    #5998
    Avatar photocandidexmedia

    However, all I’m getting is a still image (the poster). I can only play the video if I right-click on the image and click “Play”. But, the video player is supposed to look like this (same code): https://editor.p5js.org/candideu/sketches/6_R6bUaBQ. The controls are missing from the Publii Preview.

    I tried putting the Custom HTML in “Body”, “Before Post”, “After Post”, etc. and tried opening the Preview HTML in another browser (Chrome. I typically use Firefox). It seems like the scripts are being blocked for some reason…

    #6000
    Avatar photoprivii

    I suspect it’s because you’re testing locally.

    Either test online or make sure all your URLs are full path.

    This may not work locally:

    src="js/lingumania.min.js"

    Neither will this:

    src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"

    Without a protocol it will try to find the file on your computer, so you need to have `https://` in front.

    #6010
    Avatar photocandidexmedia

    I suspect it’s because you’re testing locally.

    Either test online or make sure all your URLs are full path.

    This may not work locally:

    <span class=”enlighter-text”>src=</span><span class=”enlighter-s0″>”js/lingumania.min.js”</span>
    src=”js/lingumania.min.js”

    src=”js/lingumania.min.js” Neither will this:

    <span class=”enlighter-text”>src=</span><span class=”enlighter-s0″>”//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”</span>
    src=”//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”

    src=”//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js” Without a protocol it will try to find the file on your computer, so you need to have `https://` in front.

    You were absolutely right about the second one with the source link. I added https: in front of the link, and now the media player works! Thank you so much!

    For Lingumania: I used a website link, rather than a local path initially, and it still doesn’t work. I suspect that this may be an issue on the Lingumania side.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.