Better Programming

Advice for programmers.

Follow publication

Member-only story

Angular + @ngx-translate + Typings

An Angular tutorial step-by-step: typings in @ngx-translate

Carlos Caballero
Better Programming
Published in
6 min readOct 24, 2019

--

Source: Carlos Caballero

Introduction

When you decide to use Angular in a project, it means that you’re building a large SPA (otherwise, you should think of another framework). Large projects are usually intended for users in different countries and are carried out with translations of the application.

The library that, in my opinion, is the best to implement translation in an application belonging to Angular’s ecosystem is @ngx-translate. I have used this library since the beginning because it’s simple, powerful, and very useful.

However, the biggest drawback to this library that I find is that the translations are based on a key-value translation object in which to identify the key that you want to translate, you must specify a string. The fact of using a string causes us to lose all the type control of the variables that we want to translate.

What are the problems that arise from this?

  1. We cannot know if a key is lost, incomplete, or has a typo.
  2. We do not have autocomplete, despite having nested objects that can be complex.
  3. You cannot change the name of a key automatically (refactoring) between…

--

--

Carlos Caballero
Carlos Caballero

Written by Carlos Caballero

Hi! My name is Carlos Caballero and I’m PhD. in Computer Science from Málaga, Spain. Teaching developers and degree/master computer science how to be experts!

Responses (2)

Write a response