Coder Social home page Coder Social logo

polyglot's People

Contributors

anahkiasen avatar espadav8 avatar gontard avatar jvdanilo avatar mathieudoyon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polyglot's Issues

Doesn't work with ressource

Hi,

Polyglot doesn't seems to work for me with ressource. I had 'fr' and 'en' as locales and I set 'fr' as my default. I can access my ressource with the 'en' prefix and without the prefix (french version is displayed) but when I access it with the 'fr' prefix I got an 'NotFoundHttpException'.

Thanks !

How to reduce repeating $fillable attributes in Polyglot package?

Hi, Maxime!

Recently I'am start using your package Polyglot and it very interest of me. As I understand, to correct working with package need to create at least two models, for exampe Article and ArticleLang.

class Article extends Polyglot
{
    protected $fillable = [

        'url',
        'name',
        'title',
    ];

    protected $polyglot = [

        'name',
        'title',
    ];
}

and

class ArticleLang extends Model
{
    public $timestamps = false;

    protected $fillable = [

        'name',
        'title',
    ];
}

As you can see, there are many repeatings in $fillable and $polyglot attributes. If I delete some parameters, I see MassAssingment exception.

How do you think, is there any way to reduce repeatings of field names or I do something wrong ?

Soft deletes in Laravel 4.2 + Polyglot

After updating my project to Laravel 4.2 my models that use Polyglot no longer can be deleted.
The deleted_at DB column is filled on delete but when fetching rows using Eloquent deleted items are also returned with my regular results.
Soft delete is working for Models that extend Eloquent instead of Polyglot.
Has anyone been able to get Polyglot to work with softdeletes in L4.2?
I can't even back out of this update using composer. Before my update I used the dev-develop Polyglot release on Laravel 4.1.* but Composer will not install that combination anymore.

 - anahkiasen/polyglot dev-develop requires illuminate/container ~4.2

An example class:

<?php

use Polyglot\Polyglot;

class Productgroup extends Polyglot {

    use SoftDeletingTrait;

    //protected $fillable = ['id', 'parent_id', 'image', 'order_by'];    
    protected $polyglot = ['name', 'description', 'promo_text'];
    public $imgFolder = 'productgroups/';
    protected $appends = ['productCount'];
    protected $dates = ['deleted_at'];

    public function imgUrl() {
        return Config::get('app.url') . 'public/' . Config::get('path.uploads') . $this->imgFolder . $this->image;
    }

    ....

I have added 'SoftDeletingTrait' => 'Illuminate\Database\Eloquent\SoftDeletingTrait', to my aliases in /app/config/app.php

Get model insert ID after save

After saving (insert) new model everything is successfully inserted including translation, but I can't get the newly created model record ID.

...
$record->save();
dd($record->id);

gives me null

When the model extends Eloquent the object is updated with ID after saving but Polyglot not.

Not work under Workbench

I have the models Content and ContentLang (http://pastebin.com/725xtXex)
I made the "composer dump-autoload"
But when I try to access to the main package "Teros/Content" (using Orchestra Platform) I get "Class 'ContentLang' not found".
I need to create a Facade for the model ContentLang too?

Trait

Is it possible to use this as a trait on the model class. My models already extend Ardent and php not being a single inheritance language.
Just wanted to know it can be updated to be used as a trait in my models freeing me to extend other classes like Ardent.

problem saving models

I have a "car" model
class Car extends Polyglot
class CarLang extends Model

the car contains protected $polyglot = ['name', 'description'];

saving car name and desc using
$car->fill() causes a MassAssignmentException
using $car->ar->fill([]); causes Call to a member function fill() on a non-object

any ides please?

Throws NotFoundHttpException

I did everything like in README, but it gives me an NotFoundHttpException error. It's not caused by anything else, because it runs when I remove Polyglot\PolyglotServiceProvider from providers list in app.php file.

I did find that if I uncomment these lines ( https://github.com/Anahkiasen/polyglot/blob/master/src/Polyglot/PolyglotServiceProvider.php#L82-84 ) the error disappears, so I guess there is something wrong with your Router implementation...

I'm using the latest Laravel 4.1.17

withLang problem

Don't know if is a bug or my inesperience (I'm new to laravel) but I can't use the withLang scope query, my execution of:

Article::withLang()->get();

throw this error:

Class 'Polyglot\App' not found in /vendor/anahkiasen/polyglot/src/Polyglot/Polyglot.php at line 222

I thought it was a namespace problem, so I've changed (in my code) that line adding a __ before the App:make call, so:

$eager = call_user_func_array(array(\App::make('polyglot.lang'), 'eager'), $relations);

but that code throw this other error:

Class polyglot.lang does not exist

Polyglot Router Facade breaks Route::current()

Just went to setup a new project with the package (dev-develop) and got this error

Call to a member function getUri() on null

This is being caused by

Route::current()->getUri()

Disabling the swapping of facades seems to prevent the issue. For some reason, using the polyglot router breaks the 'current' router function.

For now, I am not using localized routes so this is not an issue for me. Just posting this here as a reminder to myself if I get a chance to fix it. Or if someone else feels froggy.

Trying to get property of non-object

Hi,

Thanks for writing this package.

After adding this package to my Laravel 4.2 project I tried to get this to work. I set up everything the way I think it's supposed to be (as others pointed out the documentation could be better). Saving to the database doesn't seem to be a problem but when I want to read I get the following error:

Trying to get property of non-object (View: /Applications/MAMP/htdocs/*my view*.blade.php)

Models:

use Polyglot\Polyglot;

class Page extends Polyglot {

    use SoftDeletingTrait;

    protected $fillable = [
        'lang',
        'meta_title',
        'meta_description',
        'title',
        'page_title',
        'page_content',
    ];
    protected $polyglot = [
        'meta_title',
        'meta_description',
        'title',
        'page_title',
        'page_content',
    ];

    // ...
}
class PageLang extends Eloquent {

    public $timestamps = false;
    protected $fillable = [
        'page_id',
        'lang',
        'meta_title',
        'meta_description',
        'title',
        'page_title',
        'page_content',
    ];
}

My blade template:

$page->nl->title
/*
This is what's causing the error
$page->title doesn't produce errors but is, of course, empty
*/

Been stuck on this for a while now. Any help is greatly appreciated :-)

Incompatibility with Indonesian (when based on the ISO 639-1 spec)

This is a just a quick "heads up" as i've encountered this problem recently. I don't know whether it should be considered a bug, as it is inherent to the ISO 639-1 specification and the way Polyglot works.

The ISO 639-1 defines language as 2-letters codes. In this spirit, indonesian is defined with the code "id".

Obviously, this messes up Polyglot quiet a bit. For example, querying a Polyglotted model via Eloquent for its id (as in the primary key) doesn't work, because it tries to deliver some indonesian string...

I guess, in fewer words, ISO 639-1 adopters', beware of the indonesian conundrum...

A few updates

Well, first I should say that I've been using this package in a laravel 4.2 application in heavy production for over a year and it's worked out great for me.

With a bit of tweaking, I managed to get this, waavi/translation, and barryvdh/laravel-translation-manager working together for rather painless translation management.

The application that I'm working on now doesn't need translated just yet, though I have need for a list of countries, and I already have built a pretty complete one (with translated names) for the other application and decided to import it rather than try to rebuild it with just one language.

Soo... I needed polyglot to handle the name translation, or to implement my own relations. Thus, here I am.

There were actually only a few issues I ran into trying to implement this in Laravel 5.3.

First, your last commit, where you fixed the paths in the service provider... you only need to do that in the register function. When it is called again in the boot method, it adds the __DIR__ variable again, and the path is already absolute. It caused an error trying to publish the config, is all.

Secondly, it seems they added a new parameter to the Lang::get() function, in this commit

This causes an error to be thrown if php is in strict mode. Other than that it seems to be working fine.

If you could update those two things, it would be much appreciated. Also, you should include 'en' in the config's locales array by default, since it is the default locale anyways. the empty array had me thinking the package still wasn't working for longer than I'd like to admit.

Also, the documentation could use updating, since you don't extend the Polyglot class, but use it as a trait, now. :)

Throws exception for route groups with prefixes

With following code:

Route::groupLocale(array(
    'prefix' => 'group',
), function () {
    // code ...
});

I get the following exception:

ErrorException
trim() expects parameter 1 to be string, array given

The prefix returned by the Polyglot router looks like this:

array (size=2)
  0 => string 'en' (length=2)
  1 => string '{group}' (length=7)

though it should probably look like this:

string 'en/{group}' (length=10)

I’m using the develop branch and Laravel 4.1.

"switchLanguage" on homepage without trailing slash

Hi,

The "switchLanguage" function doesn't work as expected when I'm on the index of my site. When I'm on http://domain.com/fr and I switch to english, the url becomes http://domain.com/fr/en. It's because the regex in the function try to find 2 letters between slash and when you have just one segment with the prefix with nothing after, there is no trailing slash so the language prefix isn't replace.

Do you have a quick solution to fix this ? I tried to fix it myself but it didn't work out for the moment.

Thanks

Other languages

Now I want to add Latvian translation. It can be done by adding

public function lv()
{
    return $this->hasOne($this->getLangClass())->whereLang('lv');
}

to my model or by creating my custom Polyglot base model that I extend my other models from.

But I find it cumbersome, because there are 10 translation methods (languages) in the Polyglot class already, except Latvian (and so many more). Either add all languages (and make Polygot class huge with ~100 language methods) or better - create mechanism that makes it possible to define languages that are supported in my model!

I suggest to add this to the __get() method:

// If relation is already loaded, return it
if (array_key_exists($key, $this->relations))
{
    return $this->relations[$key];
}

if (in_array($key, $this->locales))
{
    $relation = $this->hasOne($this->getLangClass())->whereLang($key);
    return $this->relations[$key] = $relation->getResults();
}

then I just have to set supported languages in my model:

protected $locales = array('lv', 'en', 'fr');

With this solution there is no need for language methods anymore.

Please, consider this and tell me why this solution wouldn't be better! :)

Locale's with more than two characters

The UrlGenerator->locale() now returns null if the locale length in the url is not two characters. I have had to override the service provider and use my own UrlGenerator because I am using the locales zh-CN and zh-HK to differentiate mandarin and cantonese.

I am just wondering whether the UrlGenerator should in fact be returning null if the locale length is not two characters.

Many thanks

Saving translated content

Hello,

I can't seem to understand how to use of this package. I've tried different alternatives, always returns an error.

I'm trying to translate a "portfolio" model:

<?php namespace Nwidart\Portfolio\Models;

class PortfolioItem extends BaseModel
{
    protected $polyglot = ['title', 'content', 'slug'];
}

And it's -Lang table:

<?php namespace Nwidart\Portfolio\Models;

use Polyglot\Polyglot;

class PortfolioItemLang extends Polyglot
{
    protected $guarded = array('id');
    protected $table = 'PortfolioItem_Lang';
}

My controller:

<?php namespace Nwidart\Portfolio\Controllers\Admin;

use Nwidart\Portfolio\Models\PortfolioItemLang;
use Nwidart\Portfolio\Services\Validators\PortfolioItem as PortfolioItemValidator;
use View;
use Input;
use Platform\Admin\Controllers\Admin\AdminController;
use Nwidart\Portfolio\Models\PortfolioItem;

class PortfolioController extends AdminController
{
[...]
public function postCreate()
    {
        $v = new PortfolioItemValidator();

        $portfolioItem = new PortfolioItemLang();

        $portfolioItem->fill([
            'title'   => Input::get('title'),
            'content' => Input::get('description'),
            'lang' => 'fr'
        ])->save();
    }

Thank you

Searching in columns in langs table

I am having trouble finding articles by title.
The title is in the language table and the following code throws error:

$posts = BlogPosts::where('title', 'like', "'%$search%'")->get();
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'where clause' (SQL: select * from `blog_posts` where `title` like '%qwe%')

I understand that the title column is not there, because it's in the langs table, but shouldn't Polyglot search in the langs table automatically? Especially when the BlogPosts model has polyglot columns set:

protected $polyglot = ['title', 'text'];

Can you please suggest a workaround.

Undefined method error in combination with modulemanager

When i use this package with LevareCMS/modulemanager and make this call in a routes.php placed in a module folder:

Route::groupLocale(array('before' => ''), function() {

Route::get('/', function()
{
    return 'Hello world';
});

});

I get the following error:
Call to undefined method Illuminate\Translation\Translator::valid()
/­vendor/­anahkiasen/­polyglot/­src/­Polyglot/­Router.php line 44

EXTREMELY confusing docs!

Hi.

I've read through a bunch of forum posts and installation guide but can't figure out how to get the package working. I have a standard class Cars that extends Eloquent. I created a cars_lang, CarsLang model that extends Polyglot. Whenever I do Cars::find(x) I get Call to undefined method Cars::find() error.

Could someone please write clear setup instructions?

Thanks!

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.