Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep json formatted #1

Open
mtrakal opened this issue May 29, 2024 · 7 comments
Open

Keep json formatted #1

mtrakal opened this issue May 29, 2024 · 7 comments

Comments

@mtrakal
Copy link

mtrakal commented May 29, 2024

Hello, I wanted to translate grids/communicators but files are single line, so it will not be possible validate changes... Is issue for you, keep files formatted?

I use VS code to format code, is that OK for you? I'll prepare PR...

How I prepare files, are steps correct?

  • create empty user in Asterics grid app
  • import communicator
  • switch grid language in settings
  • translate all tables (I use Google Translate, Microsoft Translator and DeepL and after validate which translation is best / edit manually if not properly translated)
  • fill all translations into Asterics grid app
  • Export all tables (including Global) in all languages
  • *.grd file renamed to json and format code
  • create PR with translation
mtrakal added a commit to mtrakal/AsTeRICS-Grid-Boards that referenced this issue May 29, 2024
I used steps described in issue asterics#1
@klues
Copy link
Contributor

klues commented May 29, 2024

Wow, didn't expect any issues or pull requests on that repo that fast. It's work in progress - currently the files of default grid configurations are stored in the main AsTeRICS Grid repository, but this has some disadvantages. In the future the data will be organized within this repository (but it's not yet used).

I don't think I want to keep the configuration files as formatted json, since it's the data that is direclty downloaded and imported in AsTeRICS Grid in production and therefore it should be as small as possible.

So for translating anything I would recommend one of these:

  1. Option 1:
  2. Option 2:
    • you could format the json, add the translations directly within the json, minify the json and then do the PR with the changed file (however I imagine it's not very comfortable to edit a file with 50 000 lines)

However, I also like the idea of being able to do translations with a good diff view here on Github. So maybe we can find a way of keeping both formatted (for editing) and single-line json (for downloading). But I'm currently not sure what's the best way to achieve it. The ultimate goal would be a webpage, where it's possible to manage translations and automatically create pull requests here. Maybe we could combine it with crowdin somehow:

  • a script extracts all translations from all .grd files and stores it to separate json-files only containing the translations
  • these files are translated using crowdin
  • another script integrates the translations from crowdin to the .grd files

I think this would be a good idea, but I still have to think about the details. For now please proceede like written above.

@mtrakal
Copy link
Author

mtrakal commented May 29, 2024

Hello, it's just a good time anomaly :D.
I started translating one grid a few months ago, but never finished it (no time for it)... and now I started again...
But I want to know how the grid sources are taken because my last try to translate was long time ago and grid source could be changed in mean time. So I think about "how to synchronize" existing old / not finished/ translation with latest grid and found this new repo :).


For the future, it would be nice, if grids itself are without translations (maybe keys only or one source language?) and translations were taken in build time from some translation file/crowdin etc.. It would improve translating speed and how easily translations can be added.


I think, that you should keep json in formatted form here and minify them in compile time.
What about gzip grd/json files on webserver / when using HTTP protocol? It will reduce much more, than just minify json (don't know if it's used already)


I can minify it by myself, but doing diff is harder in that case

@mtrakal
Copy link
Author

mtrakal commented May 29, 2024

since it's the data that is direclty downloaded and imported in AsTeRICS Grid in production and therefore it should be as small as possible

What about using custom GitHub actions (you could "minify" json in step (3) before upload static pages). In case, that you plan to download jsons from GitHub pages and not using git submodule or just fetch this repo before build.

@klues
Copy link
Contributor

klues commented May 31, 2024

For the future, it would be nice, if grids itself are without translations (maybe keys only or one source language?) and translations were taken in build time from some translation file/crowdin etc.. It would improve translating speed and how easily translations can be added.

In fact in a very early version, I had grid files and translations separated. However I've changed it, because it's much more comfortable in many other aspects, e.g. at translating things within the app or at downloading single grids. However, as said, maybe we can find a way of extracting separate translations files out of the standard configs here in this repository. I think the difficult part is how to make it possible to still be able to adapt the contents of one of the grids using the app.

What about gzip grd/json files on webserver / when using HTTP protocol? It will reduce much more, than just minify json (don't know if it's used already)

Github pages (the way how the files are delivered) is automatically using gzip for .json files. That's also the reason I've named the files .grd.json here.

What about using custom GitHub actions

I've never used it, but yes, maybe it can help somehow.

@mtrakal
Copy link
Author

mtrakal commented May 31, 2024

Check this repo:
https://github.com/mtrakal/github-pages-minify-json
and output: https://mtrakal.github.io/github-pages-minify-json/

What does the magic:
mtrakal/github-pages-minify-json@d132d5b#diff-36a7fe6e9af1fc515ab07c70bee1dd529453c776db13abf7f5c6b2b3b34c4be3

&& truncate -s -1 "{}" is not necessary, but without it, it will make changes to current files.
So with call truncate, all json files content is same as now.
But UTF8 with BOM is now without BOM - if that should be issue for something, it could be encoded with BOM using someething like: https://stackoverflow.com/a/3293858/4024146
But it looks, that JSON should be without BOM: https://stackoverflow.com/questions/4990095/json-specification-and-usage-of-bom-charset-encoding

Whole workflow file:
https://github.com/mtrakal/github-pages-minify-json/blob/main/.github/workflows/jekyll-gh-pages.yml

It's just copied from "sample" to build Jekyll (what doed Github Pages pipeline).

  • need to set in repository settings:
image

@klues
Copy link
Contributor

klues commented Jun 5, 2024

Thanks for the examples, I'll have look at the Github workflows in detail after I've finished some other things regarding the grid sharing feature I'm currently working on.

In the end I think it should be possible that someone creates a PR on this repository with a new .grd backup file, an info.json with metadata about it and maybe some screenshots (so like the contents of e.g. this folder) and then some workflows / scripts are doing this:

  • extract the translations into separate .json files which then can be translated by crowdin
  • at a merge from crowdin, the translations should be re-integrated to the original .grd file
  • maybe there should be a property translatable in the ìnfo.json which specifies if crowdin translation should be possible or not. For the ARASAAC communicators, we once agreed that there should be separate versions for each language for some reasons (but maybe there could also be a "multilingual" version of the ARASAAC communicator).

@klues klues closed this as completed Jun 5, 2024
@klues klues reopened this Jun 5, 2024
@klues
Copy link
Contributor

klues commented Jul 17, 2024

I've now added quite detailed documentation to README how to add or alter configurations. For now I didn't have time to look at the Github actions, but I (or someone else) should add it in the future in order to automatically run npm run generate after all changes in the folders boards or communicators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants