Closed FranEnLaNube closed 6 months ago
Failed conditions
22.2% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)
See analysis details on SonarCloud
Catch issues before they fail your Quality Gate with our IDE extension SonarLint
I've created a new PR, #110 , so I'll close this.
Description
Changes
Swagger annotations
Following the instructions from #64 of @GabrielaMaureira , I changed the comments in dummy functions in the folder
App\Annotations\OpenApi
as implemented by @androsrivas in #91php artisan l5-swagger:generate
as is said in the documentationapp\Annotations\OpenApi\AnnotationsInfo.php
@OA\Server
. It's also possible to add a second one.app\Annotations\OpenApi\AnnotationsTags.php
controllersAnnotations\faqsAnnotations\AnnotationsFaqs.php
show()
with two endpoints. This is possible by adding two @OA Get statements for the same dummy methodshow()
in this case./faqs/{id}
to show the JSON with all the available translations./faqs/{id}?language
to show the FAQ already translated in a specific language if available.app\Annotations\OpenApi\controllersAnnotations\usersAnnotations\AnnotationsUsers.php
app\Annotations\OpenApi\modelsAnnotations\faqAnnotations\AnnotationsFaq.php
AnnotationsFaq {}
.AnnotationsFaqTranslation {}
to have the FAQ translations fields.AnnotationsFaqStored {}
to have the Schema for when a FAQ is stored.[ ] Check if this is the proper way or place to add Schemas. Mor info here:
faqController.php
index()
show()
use Astrotomic\Translatable\Validation\RuleFactory;
use \Astrotomic\Translatable\Locales;use \Astrotomic\Translatable\Locales;
.store()
RuleFactory
we are able to send one like this.RuleFactory
is used to validate all the language inputs in one shot, we don't need it any more.$dataWithLocaleKey = [$language => $validatedData];
And using the result array as input in the$faq = Faq::create($dataWithLocaleKey)->setDefaultLocale($locale);
setDefaultLocale()
'title' => ['required','string', 'max:255', 'unique:faq_translations,title'],
update()
create()
method.update()
method in Laravel doesn't update if we leave the field empty, I added the restriction to get an error in that case.RuleFactory
off from here.destroy()
If we pass the parameter in the URL deletes the FAQ translation for that language, if not, deletes the FAQ completely.
setLocale.php
App::setLocale(config('app.locale'));
inside theelse {}
in L26 it's not necessary because a fallback is configured on theconfig/app.php
file. I don't know if same happens withSession::put('locale', config('app.locale'));
which doesn't have a default value.config\l5-swagger.php
'title' => env('APP_NAME', 'ITA-Landing-API')
.env
it'll take the URL set on it, if neither is set, it'll take LocalHost and concatenate /api to it.'operations_sort' => env('L5_SWAGGER_OPERATIONS_SORT', null),
database\factories\FaqFactory.php
database\seeders\DatabaseSeeder.php
setApiLocale.php
setLocale.php
is used instead.config/app.php
'locale' => 'ca'
, it was in'en'
'fallback_locale' => 'ca'
, Set to Catalan, also was in'en'
'supported_locales' => ['ca', 'es', 'en'],
'faker_locale' => 'ca',
'ca'
.config\translatable.php
'en'
to the available languages (locales).'fallback_locale' => false,
'en'
. Changing it to false make that in case the asked translation is not available it returns anything.'ca'
returns that translation.'locales'
'format' => \Astrotomic\Translatable\Validation\RuleFactory::FORMAT_ARRAY,
resources\lang\ca\api.php
translation_not_found
,translation_key_not_available
,faq_translation_updated
andfaq_translation_deleted
'es'
y'en'
.routes/api.php
use Illuminate\Http\Request;
Route::middleware(['SetLocale'])->group(function () {}
because\App\Http\Middleware\SetLocale::class
, is already set inapp/Http/Kernel.php
, L39:protected $middlewareGroups = []
so it's not necessary to have it in this file.{language?}
to FAQ show, store , update and destroy methods to be able do call a particular language or not depending on the parameter is present or not.->prefix('faqs')
and->prefix('apps')
as it was asked in #58.To Do, pending tasks:
UserController.php
We should refactor and translate the responses for login.$validatedData
faqTests
, if later we add a user with admin role.GET
method, so it fails, because login needs to be aPOST
one.app\Http\Middleware\Authenticate.php
file.Some more interesting info
75 is the issue where @Edvenan implemented Multi-Language.
80 @levifvy add Laravel-Lang
81 @Edvenan added useful comments about localization and the implementation of Translatable Package