curl "http://localhost:8080/_/fields/translated_collection" \
-H "Content-Type: application/json;charset=utf-8" \
-H "Authorization: Bearer SOMETOKEN" \
--data '{"sort":null,"field":"translated_field","type":"string","datatype":"VARCHAR","interface":"slug","default_value":null,"options":{"placeholder":"","forceLowercase":true},"readonly":false,"required":false,"unique":false,"note":null,"hidden_detail":false,"hidden_browse":false,"primary_key":false,"validation":null,"length":200,"collection":"comparison_page","translation":{"en-US":"THIS IS TRANSLATED"}}'
(note the "translation":{"en-US":"THIS IS TRANSLATED"} key at the end of the form data)
curl "http://localhost:8080/_/collections" \
-H "Authorization: Bearer SOMETOKEN" \
-H "Content-Type: application/json;charset=utf-8"
The translated_collection collection and translated_field field both have a translation property which is an object with an en-US key, something like
"data": [
{
"collection": "translated_collection",
"fields": {
"translated_field": { ..., "translation": { "en-US": "THIS IS TRANSLATED" } }
},
"translation": { "en-US": "TRANSLATED COLLECTION NAME" },
...
}
]
The translation property on the collection is in the expected format, but the translation property on the field has not been deserialized from JSON (it's still a string):
"data": [
{
"collection": "translated_collection",
"fields": {
"translated_field": { ..., "translation": "{\"en-US\":\"THIS IS TRANSLATED\"}" }
},
"translation": { "en-US": "TRANSLATED COLLECTION NAME" },
...
}
]
I discovered this when looking into https://github.com/directus/app/issues/422 - it means that field translations can't be handled in the same way as collection name translations already are.
I tried investigating this and just got confused, but I wonder if it's something to do with the item.read filter in CoreServicesProvider.php being called for collection rows but not field rows when that endpoint is hit (that's how it appears based on putting some logging in there). I notice it is hit when the directus_settings fields are requested, and if you try adding a translation to the database for one of those fields it comes back in the expected deserialized JSON format.
master branch (and pulled just now, just in case)I think this is due to the fact that the record for this in directus_fields is still set to use TEXT instead of JSON. This field is hidden by default and isn't used anywhere (yet), so I'm not entirely sure if we should call it a bug or not :thinking:
@rijkvanzanten That was my thought too, but this is in my database (from the default install):
mysql> select * from directus_fields where collection = 'directus_fields' and field = 'translation';
+----+-----------------+-------------+------+-----------+---------+--------+------------+----------+----------+---------------+---------------+------+-------+-------+------+-------------+
| id | collection | field | type | interface | options | locked | validation | required | readonly | hidden_detail | hidden_browse | sort | width | group | note | translation |
+----+-----------------+-------------+------+-----------+---------+--------+------------+----------+----------+---------------+---------------+------+-------+-------+------+-------------+
| 37 | directus_fields | translation | json | code | NULL | 1 | NULL | 0 | 0 | 0 | 0 | NULL | 4 | NULL | NULL | NULL |
+----+-----------------+-------------+------+-----------+---------+--------+------------+----------+----------+---------------+---------------+------+-------+-------+------+-------------+
It is arguable whether this is a bug as such - I mainly raised it as a bug because of the inconsistency between getting fields from the collections endpoint vs the fields endpoint.
@binary-koan this was fixed by https://github.com/directus/api/commit/4020979eede7c6cf4f781fd3ee9277e9c964192c.
The issue here is the workflow of collection and fields is not the same for the rest of collections.
If you go to http://localhost:8080/_/fields/translated_collection/translated_field you would get the correct JSON instead of the string.
Now it parses the value of the json no matter what the field type is.
Most helpful comment
@binary-koan this was fixed by https://github.com/directus/api/commit/4020979eede7c6cf4f781fd3ee9277e9c964192c.
The issue here is the workflow of collection and fields is not the same for the rest of collections.
If you go to
http://localhost:8080/_/fields/translated_collection/translated_fieldyou would get the correct JSON instead of the string.Now it parses the value of the json no matter what the field type is.