Problems with Antl and localization


Started using Antl provider on my app… It seams like it doesnt work as I expected :slight_smile:

First thing, I think I found an issue…

If Antl provider is added inside start/app then initial migrations are impossible to run due to error: Error: ER_NO_SUCH_TABLE: Table 'starter.locales' doesn't exist
It seams like ace is for some reason checking locales table before running migrations… You can test this yourself by creating new adonis app, installing antl and running migration:run.

Second… It seams like antl is unable to translate locales that are added while app is running.
So for example… I have translated string in english for responses.something, but I don’t have the same for german (de). While application is running, I’m creating new row to locales database with de translation for responses.something. When antl.formatMessage for de is called it will throw an error: A message must be provided as a String or AST.

There are also few errors with Http request locale returning * as locale, but I think this is due to my code… So I’ll comment about it after I find out what exactly is happening.

  1. If Antl provider is added inside start/app then initial migrations are impossible to run due to error.

This happens, since you you switched to the database driver, before running the migrations.

Since Ace boots your app before running any command, the Antl provider also booted and looking for the database table and giving error, when unable to find one.

So make sure to change the driver after your migrations are in place.

  1. It seams like antl is unable to translate locales that are added while app is running.

Yes, since Antl doesn’t query the database for each call, and hence load all the strings into memory. If you are changing your strings on the fly, I recommend calling, the following method after each save.



Thanks Virk Antl.bootLoader() will help.

But about first problem, It’s the same… If you change to File loader for locales it will throw error that there is no directory…
So whenever we are putting app in production or staging we need to manualy go inside start/app.js and comment out Antl provider, run migrations and then go back and uncomment it.

This is the only way it will work… It would be great if somehow ace wouldn’t require locales table/files to run migration task. In our case this would help us automate process of putting adonis app to our staging server.

btw. any idea why from postman app locale in is set to asterix * ? Currently we are fixing this with:
if (!/^[a-z]{2}$/.test(locale)) locale = Env.get('APP_LOCALE', 'en')
Having default APP_LOCALE set in .env file

EDIT: just found out that running automated tests also fails due to this. Inside vowfile.js runner.before is calling migration:run for test db that gets reseted on runner.after.


I have added a check, where the provider doesn’t boot itself during the ace command.

Can u please install the provider from Github and try it?


Yep, this works perfectly :slight_smile:

Sorry for trouble… I think it’s better this way… Will you officialy update it or?

Thank you!

EDIT: I hope this will not break some tests that use localization? Will antl load after migration or it will never load bootLoader?

EDIT 2: Yep… This broke many more things while testing :slight_smile: It should run bootloader but somehow after migration:run… Now it throws E_RUNTIME_ERROR: Cannot use loader, since it's not booted. Make sure to call Antl.bootLoader('database') first when doing functional tests. I could start bootloader after migration manually inside vowfile but thats kinda ugly isn’t it?


Yeah I know it will break tests. Ideally there is no way to find when it should attempt to boot.

Migrations can be one example, but there can be other too, across different providers.

Lemme think of it and see what best can be done.


If this is something unique for my case… Don’t waste time please :slight_smile:


I don’t think this is unique for your case. It will happen for everyone.


I pushed another comment, where it ignores just the migration commands. Cannot think of any other neat way to fix this.


I belive this could work… Will test it a bit… Thank you!

EDIT: migration:run works flawlessly now, but node ace test that has migration:run inside vowfile runner.before will fail with no such table: locales error.


@virk any idea why sometimes returns asterix ‘*’ for locale?

Also… query parameter ?lang=xx is not working while Accept-Language header works great.

Using postman on windows with antl 2.0.4


If anyone else is failing to run tests on automated system while having Antl provider and database locales, here is how I fixed my issue while waiting official fix for this problem:

Inside package json add this script:

"test": "(export ENV_PATH=.env.test|| set ENV_PATH=.env.test) && node ace migration:run && node ace seed && node ace test --bail"

Ofcourse, adapt as you wish. For example, I have seeds for locales so I need to run seed also outside of vowfile before method.

Now instead of running node ace test, run npm run test.

This will work, because Antl is not loading on ace command migration:run, but it is loading on ace command test.