Alpine Linux only comes with an english locale by default. If you want to use the php intl extension for formatting dates, numbers and more based on different locales then this blog post will show you how to a simple way to install all locales on your Laravel Vapor deploys.
When do you need this?
Installing these locales is useful if you require use of the intl extension for formatting various strings, sorting results based on locale and it supports so many other locale based functionality.
For example, in Laravel 10.33.0 a new Number utility class was added:
1use Illuminate\Support\Number;2 3$number = Number::format(100000.123);4// 100,000.1235 6$number = Number::format(100000.123, locale: 'de');7// 100.000,123
See the Laravel Number Helper docs for more info.
This uses the intl extensions's NumberFormatter class under the hood. However, without the locales installed on vapor then the de example above would not have been
formatted correctly as any locale except en-US is missing by default.
Requirements
To use this solution you must be using in runtime: docker or runtime: docker-arm in your vapor.yml so that you are able to provide a custom <environment>.Dockerfile.
See the Vapor docs Docker Runtimes section for more information.
Installing the locales
In your Dockerfile you should add the following line between the RUN and COPY lines
1RUN apk add --no-cache icu-data-full
Afterwards your changed Dockerfile should look something like this:
1FROM laravelphp/vapor:php82-arm2 3# Install locales as alpine only has english by default.4# Used for locale based formatting using the intl extension.5RUN apk add --no-cache icu-data-full6 7# Place application in Lambda application directory...8COPY . /var/task
Conclusion
This is the best solution I have found so far for this. If you have a better solution, feel free to reach out to me on Twitter.
Syntax highlighting by Torchlight.dev