Skip to content

can we translate :attribute #157

Open

Description

@taymazmostafaei

i translated error messages but i cant translate :attribute own text.
it show input name its not correct in my support lang !
is there any way ?

Activity

  1. superdav42 commented on Nov 19, 2025

    @superdav42

    Yes, you can use aliases:
    Example:

    $validator = new Validator;
    
    // To set attribute alias, you should use `make` instead `validate`.
    $validation->make([
    	'province_id' => $_POST['province_id'],
    	'district_id' => $_POST['district_id']
    ], [
    	'province_id' => 'required|numeric',
    	'district_id' => 'required|numeric'
    ]);
    
    // now you can set aliases to the translated string:
    $validation->setAliases([
    	'province_id' => 'Provinz',
    	'district_id' => 'Bezirk'
    ]);
    $validation->setMessages([
        'required' => ':attribute ist erforderlich',
    ]);
    // then validate it
    $validation->validate();
    

    Now if province_id value is empty, error message would be 'Bezirk ist erforderlich'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions