Giter Club home page Giter Club logo

Comments (5)

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Hello,

Can you try if #13 fixes your problem (solution at the end)?
If not, can you give some more context on the issue?

from laravel-unique-translation.

Kareimovich avatar Kareimovich commented on May 29, 2024

image

My DB column

and this is how i save translations

       $model->$field = $data[$field];
       $model->save();

My Saved Value

{"ar":"\u062a\u062c\u0631\u0628\u0647","en":"test"}

i have reviewed your fix but didn't work for me @ivanvermeyen

from laravel-unique-translation.

Kareimovich avatar Kareimovich commented on May 29, 2024

Arabic is working with search but not with validation

from laravel-unique-translation.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Hello,

I've been looking into this and the following test indeed fails when using another database column type than json.

Validation should fail because there is a duplicate value, but it doesn't.

/** @test */
public function it_handles_arabic_language()
{
    Model::create([
        'slug' => ['ar' => 'جديد'],
    ]);

    $rules = [
        'slug.*' => "{$this->rule}:{$this->table}",
    ];

    $validation = Validator::make([
        'slug' => ['ar' => 'جديد'],
    ], $rules);

    $this->assertTrue($validation->fails());
}

The only way to make it pass is to change the database column type to json (text and longtext doesn't seem to work).
I don't know if this problem can be handled in the code. I'll do some research about it.

from laravel-unique-translation.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

This is probably the culprit:
https://stackoverflow.com/questions/18616682/searching-arabic-words-that-have-diacritics-in-mysql

Their solution is to add a FULLTEXT index to the column, specify the correct charset and collation and use BOOLEAN MODE in the query:

CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


INSERT INTO articles (title,body) VALUES
('الْجِنَّةِ DCKIEW', 'DAVADV الْجِنَّةِ AVADV')


SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('الجنة' IN BOOLEAN MODE);

Now, I have tried to use fulltext search, but Laravel has no built-in option to specify the BOOLEAN MODE in the query.

return DB::connection($connection)->table($table)
    ->where(function ($query) use ($column, $locale, $value) {
        $query->whereFullText($column, "\"{$locale}\": \"{$value}\"")
            ->orWhereFullText($column, "\"{$locale}\":\"{$value}\"");
        //$query->where($column, 'LIKE', "%\"{$locale}\": \"{$value}\"%")
        //    ->orWhere($column, 'LIKE', "%\"{$locale}\":\"{$value}\"%");
    });

So it didn't work.

Also, it tripped a few other tests, so I'm not sure if fulltext is even a possible solution.
The easiest way would be to use a json column.

from laravel-unique-translation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.