Handling translations in web applications can be a challenging and time-consuming task. The process entails managing various files, tracking modifications, and ensuring that translations remain current as the project progresses. These complexities can slow down development and introduce errors. That’s why we decided to create an open source solution: Kanta. In this blog post, we’ll explore the problem of managing translations in web apps, and how Kanta simplifies the process. We’ll also compare it with other translation management tools and delve into its powerful plugins.

Table of contents

    Problem with translation management in web apps

    Web applications aiming to serve a global user base often need to support multiple languages. Translating content for these applications is typically done by storing translations in static files like .po GNU gettext files, which are kept within the project's repository. However, managing these files can be complex for non-technical individuals responsible for the app's internationalization. This has led to the emergence of external services that simplify this process. Unfortunately, many of these services come with a cost and might also introduce performance issues as the backend needs to make API requests to gather translation data.

    It's worth noting a fundamental challenge with .po files: making changes requires generating, filling, and releasing these files.

    Introducing Kanta: a game-changing translation management tool

    Kanta is an open-source translation management framework designed specifically for Elixir/Phoenix projects. It aims to simplify the process of managing translations, making it more efficient and intuitive. However, it's worth noting that this efficiency isn't limited to non-technical users alone. Even technical personnel benefit from Kanta's capabilities, as it eliminates the need for the traditional release cycle, enabling faster integration of translations. By using Kanta, developers can focus on building great software rather than getting caught up in internationalisation management complexities, without changing a single line of their existing code responsible for handling translations.

    Features

    Main Kanta Features - the Elixir and Phoenix translations management tool

    Extracting missing translations

    Kanta analyses .po GNU gettext files to find missing translations, and then displays them within Kanta’s dashboard, allowing you to quickly identify which translations need to be added or updated.

    Kanta Dashboard - the Elixir & Phoenix translations management tool

    Persisting translations in the database

    Once you fill in the missing translations through Kanta’s interface, they are automatically stored in the database.

    The use of a database for storing translations also provides benefits such as easier management, versioning, and the ability to leverage the power of the database for querying and filtering translations. It's worth adding that thanks to this approach, we have eliminated the need for application releases when introducing new translations.

    Kanta Translation Page - the Elixir and Phoenix translations management tool

    Caching mechanism

    To ensure that your application runs with top-notch performance, nearly the same as if only gettext was installed, caching mechanisms were introduced. All translations stored in the database are loaded into the cache upon the application start, by default into Erlang Term Storage (ETS).

    Tracking translations progress

    One of the key features of Kanta is its ability to track the progress of translations in your application. This feature provides valuable insights into the state of your internationalization efforts and helps you effectively manage and monitor the translation process.

    The tracking feature in Kanta provides transparency and accountability, making it easier for teams to coordinate efforts and meet translation goals. It saves valuable time and reduces the risk of missing translations or leaving incomplete language support in your application.

    Kanta Tracking Translation Progress Page - the Elixir and Phoenix translations management tool

    No code changes required

    The best part is that all of those functionalities can work out-of-the-box because Kanta does not require changes in your existing code. Developers can continue using the familiar gettext function without any modifications, allowing for a smooth transition to Kanta’s translation management capabilities. This saves valuable development time and ensures that the application remains fully functional while benefiting from its powerful features.

    That’s because Kanta uses a new feature in Elixir’s gettext package, named runtime translations, which allows it to capture gettext calls and provide its own translations.

    Comparison with POEditor and Localise

    Both POEditor and Localise are widely-used web-based internationalization platforms that offer comprehensive features for translation management. However, compared to tools like them, Kanta offers several advantages.

    First, they are paid services or offer very strict translations count limits on free plans.

    The other issue is that they require communication with an external service to function. This means that every translation request from the application needs to be sent over the network, which can introduce additional latency and potential points of failure.

    In contrast, Kanta is directly plugged into the Elixir application and uses its own tables in your database, ensuring much greater performance and reducing reliance on third-party services.

    Kanta’s plugins

    Kanta goes beyond basic translation management by offering powerful plugins that enhance its capabilities as a separate dependencies. You can also create your own plugin and share it with the community to satisfy the most sophisticated requirements!

    Instruction and the current list of available plugins are available here.

    DeepL

    Not all of us are polyglots, and sometimes, we need the help of machine translation tools. That’s why Kanta provides a plugin that integrates with the DeepL API, a popular translation service offering 500,000 characters/month for free. With this plugin, users can leverage DeepL’s translation capabilities directly within Kanta and speed up the translation process.

    Kanta DeepL Plugin - the Elixir and Phoenix translations management tool

    First, add and install the dependency:

    # mix.exs
    
    defp deps
      ...
      {:kanta_deep_l_plugin, "~> 0.1.1"}
    end

    Then, to enable this feature, all you need to do is to add Kanta.Plugins.DeepL to Kanta’s plugin list:

    # config/config.exs
    
    config :kanta,
      ...
      plugins: [
        {Kanta.DeepL.Plugin, api_key: "YOUR_DEEPL_API_KEY"}
      ]

    PO Writer

    Sometimes, you may want to go back to the plain old PO files. No matter if it is because you want to create a translation back-up, migrate your codebase, or even get rid of Kanta and use another translation framework, Kanta provides all the necessary tools to get the job done.

    First, add and install the dependency:

    # mix.exs
    
    defp deps
      ...
      {:kanta_po_writer_plugin, git: "https://github.com/curiosum-dev/kanta_po_writer_plugin"},
    end

    As a next step, add Kanta.Plugins.POWriter to Kanta’s plugin list:

    # config/config.exs
    
    config :kanta,
      ...
      plugins: [
        Kanta.POWriter.Plugin
      ]

    Once you add it, a new feature appears that allows to fill .po files with translations stored in Kanta’s tables in the database.

    Summary

    Kanta offers an elegant solution to the challenges of managing translations in web apps. By providing an elegant interface, integration with the Phoenix Framework, and powerful plugins, it simplifies the internationalization process and allows non-technical people to easily manage translations without the cost of money, performance and your app’s reliability. You can check a demo application here and the Github repository here.

    We built this tool for the Elixir community, so we’d love to spread the news to as many of its members as possible. If you like it, don’t forgot to share it! If you have any feature requests, let us know in Kanta Github issues.

    5 reasons to use Kanta - the Elixir and Phoenix translations management tool

    FAQ

    What is Kanta and why is it beneficial for Elixir web apps?

    Kanta is an open-source translation management tool specifically designed for Elixir/Phoenix projects to simplify and improve the process of handling translations, making it more efficient and user-friendly.

    How does Kanta improve the translation management process?

    Kanta streamlines translation management by identifying missing translations, enabling direct database storage, and incorporating caching mechanisms, thus eliminating the need for frequent application releases for updates.

    What are the key features of Kanta in enhancing translation efficiency?

    Kanta's key features include extracting missing translations, persisting translations in the database, implementing caching for performance, and tracking translation progress for better project management.

    How does Kanta's integration with the Elixir gettext package facilitate translation management?

    Kanta leverages Elixir's gettext runtime translations feature to capture translation calls without requiring code modifications, simplifying the transition to its management system.

    What advantages does Kanta offer over other translation management tools like POEditor and Localise?

    Kanta provides a cost-effective, performance-optimized solution without relying on external services, unlike paid services like POEditor and Localise which may introduce latency and additional costs.

    How does Kanta utilize plugins to extend its capabilities?

    Kanta supports plugins, enhancing its functionality and customization, including a DeepL translation service plugin for automated translations and a PO Writer for traditional file management.

    How can one access and contribute to Kanta's development?

    Kanta is available on GitHub, and users are encouraged to contribute to its development, try out the tool, and participate in the community for further improvements.

    Artur Ziętkiewicz
    Artur Ziętkiewicz Elixir & React Developer

    Read more
    on #curiosum blog

    Context maintainability & guidelines in Elixir & Phoenix

    Context maintainability & guidelines in Elixir & Phoenix

    The concept of Phoenix Context may appear straightforward, yet its potential for significantly boosting Phoenix app maintainability is profound. However, the truth is many developers grapple with its effective implementation. In this blog post, I will unveil a strategic solution for optimizing context organization, a critical step towards sustainable and efficient Phoenix app development.