Add blog post on making JSON strings work for every language#2407
Conversation
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2407 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 672 672
Branches 211 211
=========================================
Hits 672 672 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @Utkarsh-123github, what do you think about this post? |
gregsdennis
left a comment
There was a problem hiding this comment.
I don't think there's any really wrong with the post or its content. Just a few minor editorial suggestions.
I do have a concern that this is only tangentially related to JSON Schema, though.
| } | ||
| ``` | ||
|
|
||
| The document recommends `language` for a resource-wide default language field and `direction` for a resource-wide default direction field. For localizable text objects, the examples use `lang` and `dir`, which align naturally with HTML attributes when the value is eventually displayed. |
There was a problem hiding this comment.
JSON and HTML don't need to be kept in alignment. If the recommendation is for language and direction, it might be better to keep with that rather than to introduce an unnecessary association.
If the HTML/JSON alignment is warranted, an aside explaining why would be good.
jdesrosiers
left a comment
There was a problem hiding this comment.
I do have a concern that this is only tangentially related to JSON Schema, though.
I see this as promoting best practices for schema authors, which I think is a great thing to include in this blog. But, I'd like to see a little more in the post giving guidance on how to apply these concepts using JSON Schema.
There are three patterns described in this post and you've only given a schema for one of them. I'd like to see schemas for all three patterns and examples of how to use them in a data structure the schema author is designing.
For example, the localizable text schema,
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://exampe.com/localizable-text",
"type": "object",
"properties": {
"value": { "type": "string" },
"lang": { "type": "string" },
"dir": { "enum": ["ltr", "rtl", "auto"] }
},
"required": ["value"]
}And an example of using it,
{
"type": "object",
"properties": {
"title": { "$ref": "https://example.com/localizable-text" }
}
}Then the global settings pattern,
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://exampe.com/global-localization",
"type": "object",
"properties": {
"language": { "type": "string" },
"direction": { "enum": ["ltr", "rtl", "auto"] }
}
}And an example of using it,
{
"$ref": "https://example.com/global-localization",
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"alternateTitle": { "$ref": "https://example.com/localizable-text" }
}
}Then the language map pattern,
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/language-map",
"type": "object",
"patternProperties": {
"[a-z][a-z]": { "$ref": "https://example.com/localizable-text" }
}
}And an example of using it,
{
"type": "object",
"properties": {
"title": { "$ref": "https://example.com/language-map" }
}
}I think incorporating something like that would make this a more useful resource for schema authors.
|
@jviotti I think there are several reusable structures here that could be a useful addition to your schema registry. |
|
Thanks for the suggestions! I updated the blog post. |
What kind of change does this PR introduce?
A new blog post.
Issue Number:
Screenshots/videos:
If relevant, did you update the documentation?
Summary
JSON is a very successful data format, but its string type is very simple. A value such as a title and name often needs more than Unicode characters. Consumers may need to know the language of the text and its direction, e.g., when displaying right-to-left scripts such as Arabic or Hebrew. Without that metadata, applications fall back to guessing, and guessing often fails.
The W3C Internationalization Working Group has a document on this topic: Strings on the Web: Language and Direction Metadata, which is a practical guide for specifications and formats that exchange strings. This is a blog post about the best practice.
Does this PR introduce a breaking change?
No.
Checklist
Please ensure the following tasks are completed before submitting this pull request.