Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow fix and tests update #173

Merged
merged 30 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
be19111
added .idea folder into .gitignore
Jul 19, 2024
57f6f6b
added .phpunit.cache folder into .gitignore
Jul 19, 2024
04024e7
phpunit.xml.dist schema updated
Jul 19, 2024
caf72c8
code style
Jul 19, 2024
188967c
PHPUnit replaced by Pest
Jul 19, 2024
6a62ee8
Tests refactoring
Jul 19, 2024
cfd30e9
PHP 8.0 compatibility
Jul 19, 2024
450db0d
github test runner fixed
Jul 19, 2024
9e4153b
PHP CS Fixer added and reconfigured
Jul 19, 2024
2e60a98
PHP CS Fixer configuration rules fix
Jul 19, 2024
83e3070
PHP CS Fixer configuration rules fixed
Jul 19, 2024
df9b024
Update composer.json
Jul 22, 2024
a3d8682
Update composer.json and run-tests.yml
Jul 22, 2024
394e2af
Revert "Update composer.json and run-tests.yml"
Jul 22, 2024
a5d5cc2
Update composer.json
Jul 22, 2024
ee48bd4
removed unused migration
Jul 22, 2024
5cce48e
removed constants and comments in test files
Jul 22, 2024
e03d396
removed DOCBlocks form Pest.php
Jul 22, 2024
9c5f657
removed declare(strict_types=1);
Jul 22, 2024
0fa8621
Fix styling
aon4o Jul 22, 2024
3b436f8
package ServiceProvider updated with spatie/laravel-package-tools
aon4o Jul 22, 2024
42f1b7f
updated README.md
aon4o Jul 22, 2024
76e2d5b
Fix Laravel 8 compatibility
aon4o Jul 22, 2024
b077803
grammar fix README.md
aon4o Jul 22, 2024
57e03e4
Translation loading fix
aon4o Jul 25, 2024
a43c7b5
Fix styling
aon4o Jul 25, 2024
13f0c83
Revert "Fix styling"
aon4o Jul 25, 2024
d8025b4
Revert "Translation loading fix"
aon4o Jul 25, 2024
fd3d116
$this->app['config'] -> config()
aon4o Aug 26, 2024
f0ced13
Merge branch 'main' into main
aon4o Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Check & fix styling

on: [push]
on: [ push ]

jobs:
style:
Expand All @@ -13,7 +13,7 @@ jobs:
- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes
args: --config=.php-cs-fixer.php --allow-risky=yes

- name: Extract branch name
shell: bash
Expand Down
98 changes: 49 additions & 49 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
name: run-tests

on:
- push
- pull_request
- push
- pull_request

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1, 8.0]
laravel: ['8.*', '9.*', '10.*', '11.*']
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
php: [ 8.2, 8.1, 8.0 ]
laravel: [ '8.*', '9.*', '10.*', '11.*' ]
dependency-version: [ prefer-stable ]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
run: composer test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ build
composer.lock
docs
vendor
.php_cs.cache
.php-cs-fixer.cache
.phpunit.cache
.phpunit.result.cache
.idea
30 changes: 23 additions & 7 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,46 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'array_syntax' => [
'syntax' => 'short',
],
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => [
'elements' => [
'arrays',
],
],
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
'statements' => [
'break',
'continue',
'declare',
'return',
'throw',
'try',
],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method', 'property',
'method' => 'one',
'property' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
],
])
->setFinder($finder);
55 changes: 36 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-translation-loader/run-tests.yml?branch=main&label=Tests&style=flat-square)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-translation-loader.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translation-loader)

In a vanilla Laravel or Lumen installation you can use [language files](https://laravel.com/docs/localization) to localize your app. This package will enable the translations to be stored in the database. You can still use all the features of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know and love.
In a vanilla Laravel or Lumen installation, you can use [language files](https://laravel.com/docs/localization) to
localize your app. This package will enable the translations to be stored in the database. You can still use all the
features of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know
and love.

```php
__('messages.welcome', ['name' => 'dayle']);
```

You can even mix using language files and the database. If a translation is present in both a file and the database, the database version will be returned.
You can even mix using language files and the database. If a translation is present in both a file and the database, the
database version will be returned.

Want to use a different source for your translations? No problem! The package is [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).
Want to use a different source for your translations? No problem! The package
is [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
Spatie is a web design agency based in Antwerp, Belgium.
You'll find an overview of all our open source
projects [on our website](https://spatie.be/opensource).

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-translation-loader.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-translation-loader)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can
support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards
on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

Expand All @@ -48,14 +58,14 @@ Spatie\TranslationLoader\TranslationServiceProvider::class,
You must publish and run the migrations to create the `language_lines` table:

```bash
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-migrations"
php artisan migrate
```

Optionally you could publish the config file using this command.
Optionally, you could publish the config file using this command.

```bash
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="config"
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-config"
```

This is the contents of the published config file:
Expand All @@ -78,18 +88,19 @@ return [
'model' => Spatie\TranslationLoader\LanguageLine::class,

/*
* This is the translation manager which overrides the default Laravel `translation.loader`
* This is the translation manager that overrides the default Laravel `translation.loader`
*/
'translation_manager' => Spatie\TranslationLoader\TranslationLoaderManager::class,

];
```

> **Note:** publishing assets doesn't work out of the box in Lumen. Instead you have to copy the files from the repo.
> **Note:** publishing assets doesn't work out of the box in Lumen. Instead, you have to copy the files from the repo.

## Usage

You can create a translation in the database by creating and saving an instance of the `Spatie\TranslationLoader\LanguageLine`-model:
You can create a translation in the database by creating and saving an instance of
the `Spatie\TranslationLoader\LanguageLine`-model:

```php
use Spatie\TranslationLoader\LanguageLine;
Expand All @@ -101,7 +112,8 @@ LanguageLine::create([
]);
```

You can fetch the translation with [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):
You can fetch the translation
with [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):

```php
__('validation.required'); // returns 'This is a required field'
Expand All @@ -111,15 +123,19 @@ app()->setLocale('nl');
__('validation.required'); // returns 'Dit is een verplicht veld'
```

You can still keep using the default language files as well. If a requested translation is present in both the database and the language files, the database version will be returned.
You can still keep using the default language files as well. If a requested translation is present in both the database
and the language files, the database version will be returned.

If you need to store/override json translation lines, just create a normal LanguageLine with `group => '*'`.
If you need to store/override JSON translation lines, just create a normal LanguageLine with `group => '*'`.

## Creating your own translation providers

This package ships with a translation provider than can fetch translations from the database. If you're storing your translations in a yaml-file, a csv-file, or ... you can easily extend this package by creating your own translation provider.
This package ships with a translation provider that can fetch translations from the database.
If you're storing your translations in a yaml-file, a csv-file, etc.,
you can easily extend this package by creating your own translation provider.

A translation provider can be any class that implements the `Spatie\TranslationLoader\TranslationLoaders\TranslationLoader`-interface. It contains only one method:
A translation provider can be any class that implements
the `Spatie\TranslationLoader\TranslationLoaders\TranslationLoader`-interface. It contains only one method:

```php
namespace Spatie\TranslationLoader\TranslationLoaders;
Expand All @@ -137,7 +153,7 @@ Translation providers can be registered in the `translation_loaders` key of the

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

## Testing

Expand All @@ -151,7 +167,8 @@ Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTI

## Security

If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.
If you've found a bug regarding security, please mail [security@spatie.be](mailto:security@spatie.be) instead of using
the issue tracker.

## Credits

Expand Down
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
"php": "^8.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"spatie/laravel-package-tools": "^1.12"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0|^10.5",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0"
"friendsofphp/php-cs-fixer": "^3.59",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"pestphp/pest": "^1.23|^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,14 +38,18 @@
},
"autoload-dev": {
"psr-4": {
"Spatie\\TranslationLoader\\Test\\": "tests"
"Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/pest",
"lint": "vendor/bin/php-cs-fixer fix"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_language_lines_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ return new class extends Migration
public function up(): void
{
Schema::create('language_lines', function (Blueprint $table) {
$table->bigIncrements('id');
$table->id();
$table->string('group')->index();
$table->string('key');
$table->json('text');
Expand Down
29 changes: 29 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache"
>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./app</directory>
<directory>./src</directory>
</include>
</source>
</phpunit>
Loading