Replies: 8 comments 5 replies
-
Unfortunately, I've never built big multilingual sites with Mavo. So the following thoughts are only my vision and not the best practice as we understand it. For site content (blog posts, articles, advertisements, etc.), I would stick to separate JSON files for every supported language. The dynamic nature of Mavo backends is for the rescue—they are “live” so we can use expressions inside the corresponding attributes. A while ago I built a pen to illustrate this: https://codepen.io/dmitrysharabin/pen/OeajoX. It seems to me, your first option is exactly about that. For UI elements, I would use either a Suppose we have a couple of localization plugins:
Mavo.Locale.register("en", {
file: "File",
edit: "Edit"
});
Mavo.Locale.register("ru", {
file: "Файл",
edit: "Правка"
});
Mavo.Locale.register("fr", {
file: "Fichier",
edit: "Modifier"
}); We need to include them in our page: <head>
...
<script src="en.js"></script>
<script src="ru.js"></script>
<script src="fr.js"></script>
...
</head> And then we can use them like so: <body>
...
<select property="language">
<option value="en">🇺🇸 English</option>
<option value="fr">🇫🇷 Français</option>
<option value="ru">🇷🇺 Русский</option>
</select>
...
<nav lang="[language]">
<ul>
<li>[phrase("file", language)]</li>
<li>[phrase("edit", language)]</li>
</ul>
</nav>
...
</body> I made a pen to illustrate it and found out that we have a regression: the UPDATE: The bug is fixed. 🥳
I didn't quite get it. Could you please elaborate a bit? |
Beta Was this translation helpful? Give feedback.
-
This could work in a 'flat' data source file, like 1 row database, or json source, but I would have 1 row per language "drink-english" : "Drink Kvas"; But it's not the kind of humanly readable file, that's why I'm looking for a 2 dimensional table and wondering if there’s a way to do it with mavo |
Beta Was this translation helpful? Give feedback.
-
I believe I could find a way to help you. It's based on using the Google Sheets plugin. First of all, we need to create a table with all the localization strings in every supported language. Something like this one: Then, with the help of the Then, we can give each of these ranges a name, corresponding to the value of a property you use in your app to track the language chosen by a user. N.B. I would recommend giving names to half-opened ranges. For example, when I gave a name to a range with the localization strings in English, I used this range: And since Mavo supports expressions in storage attributes and the Google Sheets plugin supports named ranges, we can easily switch languages. I put it all together in this pen: https://codepen.io/dmitrysharabin/pen/podexaX. The source table I work with is here: https://docs.google.com/spreadsheets/d/14bzCuziKutrA3iESarKoj2o56dhraR8pzuFAuwTIo-g/edit?usp=sharing Is that what you need? |
Beta Was this translation helpful? Give feedback.
-
That's a smart approach, using range source I guess it could be the same as selecting a view for a database (in case you're not using Google data source) But then trying to integrate user content like: where: How to separate "translation" data, from "content" data?
|
Beta Was this translation helpful? Give feedback.
-
Looking at your amazing memory game https://dmitrysharabin.github.io/mavo-memory-game/ I found a way to get a value from one app to another one, and made this codepen: But I can't figure in this case, how to display previous "language" data Is there a way to ask mavo to display something like: if "english" language selected if "french" language selected |
Beta Was this translation helpful? Give feedback.
-
That's exactly the approach I was going to suggest to you: divide data between two apps. I updated the pen to reflect my proposal: https://codepen.io/dmitrysharabin/pen/podexaX. The main downside I see in this approach is that in one app we must specify all the properties we are going to use in another one. It might be I'm simply not aware of another (native for Mavo) way to use one app's data in another app without JS. @LeaVerou do you have any hints for us? I was trying to use these hooks. However, it didn't work—the corresponding expressions are not being updated. I definitely miss something. Mavo.hooks.add("render-start", async function (env) {
if (this.id !== "main") {
return;
}
await Mavo.all["i18n"].dataLoaded;
env.data.i18n = Mavo.all["i18n"].getData()?.[0];
});
Mavo.hooks.add("getdata-end", function (env) {
// Make sure we're in the right Mavo app
if (this.id !== "main") {
return;
}
// Undo env.data transformation before saving
delete env.data.i18n;
}); Here is the pen with my experiments: https://codepen.io/dmitrysharabin/pen/oNoWoOa. |
Beta Was this translation helpful? Give feedback.
-
AFAIK, there is no way to do it in Mavo. Yet. :) |
Beta Was this translation helpful? Give feedback.
-
We should create a server for Translation, I hope GitHub will do this, open source. not just by excel file. |
Beta Was this translation helpful? Give feedback.
-
Hi,
In your experience, what would be the best way to manage a multi-language site with MAVO?
Mavo already provide some nice and cool ways for localization )
But I'm not sure that using for example for a large site is the best way to manage it: could be quiclky a big pain.
1/ The first idea that came to my mind was to manage several JSON files in source (1 for each language), and change the source trought a drop-down selector.
But I thought that it would be quite difficult to manage on the backend, all files side by side for a translator:
2/ Second idea that came to me was to play with "text" & "localization", maybe I can extend that file, but then, I would be with a huge file, and return to case 1, where I would have to open multiple files. By the way, I'm not sure about documentation on how to do it (is there any exemple somewhere, if this is the right solution?)
3/ Then I remembered that a few long years ago, a simple table, with one column per language was the "humanly" manageable way :
So would it be possible to tell MAVO to take all the fields in a specific column to build the site?
What is your experience on the subject, for large web sites, and what advice would you give?
Beta Was this translation helpful? Give feedback.
All reactions