Upgrade to Pro — share decks privately, control downloads, hide ads and more …

করো: Translating Code to Other (Human) Languages, and Back Again

করো: Translating Code to Other (Human) Languages, and Back Again

Javascript runs on nearly any platform. Most languages can compile to Javascript. It’s well-positioned to become the lingua franca of programmers, with one problem: Like most programming languages, Javascript is based on English. 89% of the world’s population doesn’t speak any English. Many of those people can’t even read the Latin script. If we want Javascript to be a lingua franca, we need to ensure it is accessible to all people, regardless of their native language.

Let’s look at the barriers that non-native speakers face when contributing to OSS Javascript projects and what it would take to remove them entirely, so that two developers could collaborate without speaking the same language. We will see what techniques Javascript can borrow from other languages by taking a look at করো (koro), a project which adds Bengali support to the Go compiler. And, we will learn enough about compilers and character encoding to answer the eternal question: “Could we do this in Javascript?”

Aditya Mukerjee

June 01, 2019
Tweet

More Decks by Aditya Mukerjee

Other Decks in Technology

Transcript

  1. : Translating Code to Other
    (Human) Languages
    and Back Again
    @chimeracoder
    Aditya Mukerjee
    Systems Engineer, Stripe

    View Slide

  2. 95%
    of the world doesn’t speak
    English as their first language
    89%
    of the world doesn't speak
    English at all
    @chimeracoder

    View Slide

  3. Software is eating the world
    @chimeracoder
    (and Javascript is eating software)

    View Slide

  4. @chimeracoder
    Software is a powerful enabling force
    Software reflects the people who build it

    View Slide

  5. View Slide

  6. “I would have thought it would be useful to NATO, because they had the
    common verbs for the things they were going to do. And the nouns, they’d
    just have to have a dictionary for things they were referring to for inventory
    control…. They’d have common nouns throughout NATO, and they could
    make a dictionary of common verbs and translate the program. You could
    write one in English and you could translate it and it could go to [the other
    language]. No problem, you’d have communication. It would be a limited
    vocabulary.”
    - Grace Hopper
    @chimeracoder

    View Slide

  7. github.com/ChimeraCoder/koro
    (koro)

    View Slide

  8. package main
    import "fmt"
    func main() {
    if true {
    fmt.Printf(“hello, world!\n")
    }
    }
    @chimeracoder

    View Slide

  9. main
    "fmt"
    main(){
    true {
    fmt.Println(”hello, world!!\n")
    }
    }
    @chimeracoder

    View Slide

  10. @chimeracoder

    View Slide


  11. View Slide

  12. gofmt
    korofmt
    @chimeracoder

    View Slide

  13. View Slide

  14. Automatic source code translation
    • Bidirectional translation layers
    • Localize source code as a commit hook
    @chimeracoder

    View Slide

  15. Structuring Code

    View Slide

  16. Naming Schemes
    @chimeracoder
    readFoo()
    writeFoo()
    then()
    (etc.)
    foo ()
    foo ()
    ()

    View Slide

  17. Could we do this in Javascript?

    View Slide

  18. Character encoding
    Go:
    • Source code is required by the language spec to be UTF-8
    • Strings (and byte arrays) are internally treated as UTF-8
    JavaScript:
    • Source code can have any encoding supported by the interpreter
    • JavaScript: Strings are internally treated as... uhhh… wait…
    …what?

    View Slide

  19. @chimeracoder

    View Slide

  20. Could we do this in Javascript?

    View Slide

  21. Could we do this in Javascript?
    ¯\_()_/¯

    View Slide

  22. Localizing Error Messages

    View Slide

  23. type error interface {
    Error() string
    }
    @chimeracoder

    View Slide

  24. @chimeracoder
    Cannot cast parameter type from type “System.String” to
    argument type “System.String”
    Uncaught SyntaxError: Unexpected token ILLEGAL

    View Slide

  25. The only thing worse than a cryptic error message is a cryptic error
    message in a foreign language that you can’t understand
    @chimeracoder

    View Slide

  26. Where do we go from here?

    View Slide

  27. 95%
    of the world doesn’t speak
    English as their first language
    89%
    of the world doesn't speak
    English at all
    @chimeracoder

    View Slide

  28. Aditya Mukerjee
    @chimeracoder
    https://github.com/ChimeraCoder

    View Slide