Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud217TR committed Jun 21, 2024
1 parent ed583aa commit 0de942e
Show file tree
Hide file tree
Showing 30 changed files with 561 additions and 552 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: :vendor_name
github: Mahmoud217TR
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a
url: https://github.com/Mahmoud217TR/auto-files-localizer/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas
url: https://github.com/Mahmoud217TR/auto-files-localizer/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/:vendor_name/:package_name/security/policy
url: https://github.com/Mahmoud217TR/auto-files-localizer/security/policy
about: Learn how to notify us for sensitive bugs
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog

All notable changes to `:package_name` will be documented in this file.
All notable changes to `auto-files-localizer` will be documented in this file.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) :vendor_name <author@domain.com>
Copyright (c) Mahmoud217TR <mahmoud17tr@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
128 changes: 92 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,124 @@
# :package_description
# Auto Files Localizer for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
<!--delete-->
---
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
[![Latest Version on Packagist](https://img.shields.io/packagist/v/mahmoud217tr/auto-files-localizer.svg?style=flat-square)](https://packagist.org/packages/mahmoud217tr/auto-files-localizer)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/mahmoud217tr/auto-files-localizer/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mahmoud217tr/auto-files-localizer/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/mahmoud217tr/auto-files-localizer/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/mahmoud217tr/auto-files-localizer/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/mahmoud217tr/auto-files-localizer.svg?style=flat-square)](https://packagist.org/packages/mahmoud217tr/auto-files-localizer)

1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
3. Have fun creating your package.
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---
<!--/delete-->
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
**Easy and Efficient Localiztion**

## Support us
A Laravel Localization package that auto generate json locale files

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
![logo](assets/auto-files-localizer.svg)

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).
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Config](#config)
- [Usage](#usage)
- [Dynamic Mode](#dynamic-mode)
- [Extraction Mode](#extraction-mode)
- [Testing](#testing)
- [Changelog](#changelog)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

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).
## Features

* Supports Laravel (8.X, 9.X, 10.X, 11.X).
* 2 Modes (Dynamic Mode, Extraction Mode).
* Fast and reliable.

## Installation

You can install the package via composer:

```bash
composer require :vendor_slug/:package_slug
composer require mahmoud217tr/auto-files-localizer
```

You can publish and run the migrations with:
## Config

To publish the package configuration file `config/auto-localizer.php` use the following command:

```bash
php artisan vendor:publish --tag=":package_slug-migrations"
php artisan migrate
php artisan vendor:publish --tag="auto-files-localizer-config"
```

You can publish the config file with:
## Usage

It will automatically generate the locale `.json` file where the localized new words are sorted alphabetically.

**There are 2 modes for the package**

### Dynamic Mode

In this mode the translations will be generated dynamically **(On Request)** which means on upon calling the translation function the package will dynamically detect the current language and add the translations to the corresponding `JSON` file.

#### Notes
* Note that this mode shouldn't work on production for performance purposes, but if you want to change this behavior via the configuration file.

* This mode is not recommended using with `vite development` mode. If you want to use it please **build your assets first** using `npm run build` then activate the auto translation mode. **OTHERWISE YOUR APP WILL STUCK IN RELOAD LOOP**

#### Activiation
To activate the `dynamic` mode on `non-production` environment just add the following line to the `.env` file:

```bash
php artisan vendor:publish --tag=":package_slug-config"
```
AUTO_LOCALIZER_ENABLED=true
```

And that's about it the autotranslator will add transaltions to there files sorted alphabetically.
To deactivate the dynamic mode just set the previous value to `false`.

#### Configurations

This is the contents of the published config file:
This mode have the following configurations:

```php
return [
];
'dynamic' => [
# Controls if the dynamic mode should work or not on non-production environments
'enabled' => (bool) env('AUTO_LOCALIZER_ENABLED', false),
# Controls if the dynamic mode should work or on production environment (compined with the previous option)
'production' => false,
],
```

Optionally, you can publish the views using
### Extraction Mode

```bash
php artisan vendor:publish --tag=":package_slug-views"
In this mode the translations will be extracted automatically from `views` or `php` files detecting translation functions adding the translations to the corresponding `JSON` file.

#### Command

To extract the translations for a specific locale (`ar` for example) run the following command:

```shell
php artisan auto-localizer:extract ar
```

## Usage
The previous command will translate all `non-localized` phrases and all `ar-localized` phrases only.

#### Configurations

This mode have the following configurations:

```php
$variable = new VendorName\Skeleton();
echo $variable->echoPhrase('Hello, VendorName!');
'extraction' => [
# The directories where the translation scanner will scan
'directories' => [
'resources/views',
],
# The file patterns that the translation scanner will scan
'patterns' => [
'*.php'
],
# The translation functions or directives that scanner will detect (you should add your custom functions here)
'functions' => [
'__',
'trans',
'@lang',
],
],
```

## Testing
Expand All @@ -85,7 +141,7 @@ Please review [our security policy](../../security/policy) on how to report secu

## Credits

- [:author_name](https://github.com/:author_username)
- [Mahmoud Mahmoud](https://github.com/Mahmoud217TR)
- [All Contributors](../../contributors)

## License
Expand Down
25 changes: 25 additions & 0 deletions assets/auto-files-localizer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 26 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
{
"name": ":vendor_slug/:package_slug",
"description": ":package_description",
"name": "mahmoud217tr/auto-files-localizer",
"description": "Laravel Localization package that auto generate json locale files",
"keywords": [
":vendor_name",
"Mahmoud217TR",
"laravel",
":package_slug"
"auto-files-localizer"
],
"homepage": "https://github.com/:vendor_slug/:package_slug",
"homepage": "https://github.com/mahmoud217tr/auto-files-localizer",
"license": "MIT",
"authors": [
{
"name": ":author_name",
"email": "[email protected]",
"name": "Mahmoud Mahmoud",
"email": "[email protected]",
"homepage": "https://github.com/Mahmoud217TR",
"role": "Developer"
}
],
"require": {
"php": "^8.2",
"php": "^8.0",
"spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^10.0||^11.0"
"illuminate/contracts": "^10.0||^11.0",
"illuminate/config": "^9.0|^10.0|^11.0",
"illuminate/console": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"illuminate/filesystem": "^9.0|^10.0|^11.0",
"illuminate/translation": "^9.0|^10.0|^11.0",
"symfony/finder": "^5.1|^6.0|^7.0"
},
"require-dev": {
"laravel/pint": "^1.14",
Expand All @@ -30,24 +37,26 @@
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"spatie/laravel-ray": "^1.35"
"phpstan/phpstan-phpunit": "^1.3"
},
"autoload": {
"psr-4": {
"VendorName\\Skeleton\\": "src/",
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
"Mahmoud217TR\\AutoFilesLocalizer\\": "src/"
}
,
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"VendorName\\Skeleton\\Tests\\": "tests/",
"Mahmoud217TR\\AutoFilesLocalizer\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"clear": "@php vendor/bin/testbench package:purge-auto-files-localizer --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": [
"@composer run prepare",
Expand All @@ -73,11 +82,8 @@
"extra": {
"laravel": {
"providers": [
"VendorName\\Skeleton\\SkeletonServiceProvider"
],
"aliases": {
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
}
"Mahmoud217TR\\AutoFilesLocalizer\\AutoFilesLocalizerServiceProvider"
]
}
},
"minimum-stability": "dev",
Expand Down
64 changes: 64 additions & 0 deletions config/auto-files-localizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Translation Path
|--------------------------------------------------------------------------
|
| This option defines the directory where the translated files will be saved.
| By default, it uses the 'resources/lang' directory of your Laravel app.
|
*/
'path' => default_languages_path(),

/*
|--------------------------------------------------------------------------
| Extraction mode options
|--------------------------------------------------------------------------
|
| 1- directories:
| This option determines what directories the translation scanner should scan.
|
| 2- patterns:
| This option determines what pattern of files the translation scanner should scan.
|
| 3- functions:
| This option determines functions or blade directives that the strings will be extracted from.
| You should add any custom defined functions or directives used for translation here.
|
*/
'extraction' => [
'directories' => [
'resources/views',
],
'patterns' => [
'*.php'
],
'functions' => [
'__',
'trans',
'@lang',
],
],

/*
|--------------------------------------------------------------------------
| Dynamic mode options
|--------------------------------------------------------------------------
|
| 1- enabled (Auto Localizer Enabled):
| This option determines whether the auto localizer functionality is enabled.
| When set to true, the package will save translations automatically.
|
| 2- production (Production Mode):
| This option controls whether the auto localizer functionality is active in
| the production environment. If set to true, the functionality will work
| in all environments, including production.
|
*/
'dynamic' => [
'enabled' => (bool) env('AUTO_LOCALIZER_ENABLED', false),
'production' => false,
],
];
6 changes: 0 additions & 6 deletions config/skeleton.php

This file was deleted.

Loading

0 comments on commit 0de942e

Please sign in to comment.