Code Monkey home page Code Monkey logo

Comments (7)

anthonyjb avatar anthonyjb commented on August 18, 2024

So I haven't added support for translations at the moment (and I really don't have a good excuse for not doing so). There's a tiny amount of text that would requires translation (in a quick tally I found approx 40 all of which are short).

I think setting the language should be an option against the namespace ContentTools.LANGUAGE = 'en' and as you say allowing a languages.json file to be defined/loaded with additional translations.

I've marked this as an enhancement and will add it to the mile stone in the readme.

from contenttools.

mlshvdv avatar mlshvdv commented on August 18, 2024

@anthonyjb I can help with russian translation.

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

@MalyshevDmitry thank you!

from contenttools.

tvaliasek avatar tvaliasek commented on August 18, 2024

I'm trying to write my own integration of translation, but I must face the fact, that every UI component was already created before the translation was loaded. For example the labels of tools can't be set properly, and fallback to default label text is applied. Is there any way to wait for the moment when translation is ready and defer elements creation?

I have tried to use some constructions with events and/or setInterval function, but without success.

namespace.coffee:

# Default language url - tvaliasek
    LANGUAGE_URL: '/assets/content-tools/lang/en_US.json'
    STRINGS: null
    LANG_LOADING: false 

# ...

# loading function for language file. Based on https://coffeescript-cookbook.github.io/chapters/ajax/ajax_request_without_jquery - tvaliasek
setLangUrl: (url) -> 
      ContentTools.LANGUAGE_URL = url
      ContentTools.LANG_LOADING = true
      req = new XMLHttpRequest()
      req.addEventListener 'readystatechange', ->
        if req.readyState is 4
          successResultCodes = [200, 304]
          if req.status in successResultCodes
            data = eval '(' + req.responseText + ')'
            console.log 'Loaded language file: ', data.langName
            ContentTools.STRINGS = data;
          else
            console.error 'Error loading language file.'
          ContentTools.LANG_LOADING = false
      req.open 'GET', url, false
      req.send()

# ...

tools.coffee:

# ...

# Common tools

class ContentTools.Tools.Bold extends ContentTools.Tool

    # Make the current selection of text (non)bold (e.g <b>foo</b>).

    ContentTools.ToolShelf.stow(@, 'bold')

    @label = if ContentTools.STRINGS is null then 'Bold' else ContentTools.STRINGS.tools.labels.bold
    @icon = 'bold'
# ...

init of editor:

            ContentTools.setLangUrl('/js/content-tools/lang/cs_CZ.json');

            ContentTools.StylePalette.add([
                new ContentTools.Style('Warning', 'alert alert-warning', ['p','div']),
                new ContentTools.Style('Button', 'btn btn-primary', ['a'])
            ]);

            var editor = ContentTools.EditorApp.get();
            editor.init('*[data-editable]', 'data-name'); 

cs_CZ.json:

{
    "langName": "Česky - cs_CZ",
    "tools": {
        "labels":{
            "bold": "Tučně",
            "italic": "Kurzívou",
            "link": "Vložit odkaz"
        }
    }
}

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

@tvaliasek my plan for tomorrow and over the weekend is to look into adding support for multiple languages. I have an approach that I've used on other libraries I've worked on so I don't think it will take me too long to put something together (and I have volunteers for French and Russian so far and hopefully others will help translate more languages too).

The only nasty bit right now I can think of is translating the helper titles in ContentEdit, as the content is currently part of the CSS - so I'll have to change that.

Once my solution is in the dev branch I'll let you know and get you to review.

from contenttools.

tvaliasek avatar tvaliasek commented on August 18, 2024

Ok, I was just curious how it works. Sign me as volunteer for Czech translation.

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

Basic multilingual support is now available - I've posted a short tutorial on how to use it. Right now though we're a tad short on languages (Pig Latin is the only one available right now - which is of no use other than to test the concept).

Guide available here: http://getcontenttools.com/tutorials/multilingual-support

from contenttools.

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.