Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

khatran's avatar

Translate a text paragraph from English to Vietnamese

I have a form as:

<form class="form-horizontal form-label-left form_create" action="{{ route('admin.colors.store') }}" role="form" method="POST" enctype="multipart/form-data">
                        {{ csrf_field() }}
                        <div class="form-group row">
                            <div class="col-md-2">
                                <label for="ex1">Mã màu</label>
                                <input class="form-control" id="ex1" type="color" value="#000000">
                            </div>
                            <div class="col-md-3">
                                <label for="ex2">Tên màu</label>
                                <value for="1" style="display:none">Asia,Southern Asia</value>
                                <input class="form-control" id="ex2" type="text" readonly>
                            </div>
                            <div class="col-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Save
                                </button>

                                <a class="btn btn-primary" href="{{ route('admin.colors.create') }}">
                                    Cancel
                                </a>
                            </div>
                        </div>
                    </form>
                            

I used jquery to get color_name push into input[type='text'] as:

<script type="text/javascript" src="http://chir.ag/projects/ntc/ntc.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('input[type=color]').change(function(){
            var value = $(this).val();
            var n_match  = ntc.name(value);
            n_name = n_match[1];
            $(this).closest(".form-group").find("#ex2").val(n_name);
        });

    })
    
</script>

It work very good! But its language is English. I am Vietnamese, so I want it translate color name to Vietnamese. I try use this library (https://cloud.google.com/translate/docs/reference/libraries#client-libraries-usage-php) but it is error:

{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": "The request is missing a valid API key.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}

Everyone help me solve this problem. Thank you very much

0 likes
1 reply
mvd's avatar

Hi @khatran,

The error is clear, you are not adding a valid key when you do a request.

Did you create service account key?

Please or to participate in this conversation.