Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cfd82af
wip: proof of concept for json translatable
WovenCoast Feb 19, 2025
4e14139
test: run workflow for dev branch
WovenCoast Feb 19, 2025
a0c9d54
feat: add db translatable
WovenCoast Feb 20, 2025
1a60199
fix: factories faker compatibility and unit tests syntax error
WovenCoast Feb 20, 2025
12795f1
test: support for laravel 9
WovenCoast Feb 20, 2025
d64415b
coverage: run
WovenCoast Feb 20, 2025
9532d27
Update code coverage badge
github-actions[bot] Feb 20, 2025
70ee66a
coverage: fix
WovenCoast Feb 20, 2025
9896826
Merge remote-tracking branch 'origin/dev' into dev
WovenCoast Feb 20, 2025
6c8c41a
coverage: remove unneccessary files
WovenCoast Feb 23, 2025
63ca262
Update code coverage badge
github-actions[bot] Feb 23, 2025
c3f60df
docs: update README.md
WovenCoast Feb 23, 2025
d94a4d1
coverage: improve code coverage
WovenCoast Feb 23, 2025
a559b6d
Update code coverage badge
github-actions[bot] Feb 23, 2025
c973200
docs: update README.md
WovenCoast Feb 23, 2025
a22b78c
coverage: add addTranslation function
WovenCoast Feb 23, 2025
b3fd6a7
Update code coverage badge
github-actions[bot] Feb 23, 2025
fa0a757
fix: add translation for locales that are not allowed
WovenCoast Feb 23, 2025
c55e839
wip: eod
WovenCoast Feb 23, 2025
5f24405
feat!: add translation via setter
WovenCoast Feb 24, 2025
019855f
coverage: improve code coverage
WovenCoast Feb 24, 2025
561b4af
coverage: fix compatibility issues with phpunit 9.5.10
WovenCoast Feb 24, 2025
d4f0c31
Update code coverage badge
github-actions[bot] Feb 24, 2025
f1911c4
docs: update docs
WovenCoast Feb 24, 2025
279689b
feat: add config option for lang suffix fallback
WovenCoast Feb 24, 2025
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
20 changes: 20 additions & 0 deletions .github/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 65 additions & 55 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
name: tests

on:
pull_request:
branches:
- main
push:
branches:
- main
pull_request:
branches:
- main
push:
branches:
- main
- dev

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

strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.3, 8.2, 8.1 ]
laravel: [ 11.*, 10.*, 9.* ]
stability: [ prefer-lowest, prefer-stable ]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
exclude:
- laravel: 11.*
php: 8.1

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

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

- name: Install SQLite 3
run: |
sudo apt-get update
sudo apt-get install sqlite3 -y

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: none\

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

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

strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.3, 8.2, 8.1 ]
laravel: [ 11.*, 10.*, 9.* ]
stability: [ prefer-lowest, prefer-stable ]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
exclude:
- laravel: 11.*
php: 8.1

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

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

- name: Install SQLite 3
run: |
sudo apt-get update
sudo apt-get install sqlite3 -y

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: ${{ startsWith(github.event.head_commit.message, 'coverage') && matrix.php == '8.3' && matrix.laravel == '11.*' && matrix.stability == 'prefer-stable' && 'xdebug' || 'none' }}

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

- name: Execute tests
run: |
vendor/bin/phpunit ${{ startsWith(github.event.head_commit.message, 'coverage') && matrix.php == '8.3' && matrix.laravel == '11.*' && matrix.stability == 'prefer-stable' && '--coverage-clover=clover.xml' || '' }}

- name: Make code coverage badge
if: startsWith(github.event.head_commit.message, 'coverage') && matrix.php == '8.3' && matrix.laravel == '11.*' && matrix.stability == 'prefer-stable'
uses: timkrase/phpunit-coverage-badge@v1.2.1
with:
coverage_badge_path: .github/coverage.svg
push_badge: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,59 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/javaabu/translatable.svg?style=flat-square)](https://packagist.org/packages/javaabu/translatable)
[![Test Status](../../actions/workflows/run-tests.yml/badge.svg)](../../actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/javaabu/translatable.svg?style=flat-square)](https://packagist.org/packages/javaabu/translatable)

![Code Coverage](./.github/coverage.svg)


## Introduction

Adds multi-lingual to Laravel models

To get started with this package, you can simply add `DbTranslatableSchema::columns($table);` or `JsonTranslatableSchema::columns($table);` to your migration `up` function.

```php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Javaabu\Translatable\DbTranslatable\DbTranslatableSchema;

return new class extends Migration {
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();

...

DbTranslatableSchema::columns($table);
});
}

public function down(): void
{
Schema::dropIfExists('posts');
}
};
```

And then all you need to do is add the `Translatable` implementation using the `IsDbTranslatable` or `IsJsonTranslatable` trait.

```php
...

class Post extends Model implements Translatable
{
use IsDbTranslatable;

...
```

Now, your models will automatically be translated according to the current `app()->getLocale()`. To add different translations, all you need to do is

```php
// to add title for dv language
$post->title_dv = "Mee Dhivehi title eh";
```

## Documentation

You'll find the documentation on [https://docs.javaabu.com/docs/translatable](https://docs.javaabu.com/docs/translatable).
Expand Down Expand Up @@ -43,6 +90,7 @@ If you discover any security related issues, please email [info@javaabu.com](mai
- [Javaabu Pvt. Ltd.](https://github.com/javaabu)
- [Arushad Ahmed (@dash8x)](http://arushad.com)
- [Xylam (@Xylam)](https://github.com/Xylam)
- [FlameXode (@WovenCoast)](https://github.com/WovenCoast)
- [All Contributors](../../contributors)

## License
Expand Down
Loading