WonderCMS / wondercms

Fast and small flat file CMS (5 files). Built with PHP, JSON database.
https://wondercms.com
MIT License
659 stars 165 forks source link

[Plugin request] Multi-language #40

Closed AndiLeni closed 4 years ago

AndiLeni commented 7 years ago

Hello, I wanted to know whether it would be possible to implement a language switcher for the admin interface. A possible solution would be using i18njs. The work needed to realize this should not be that big because wCMS already relies on JSON database. I'd love to hear your opinion.

robiso commented 7 years ago

I don't think this wouldn't be an easy mission, as almost everything in the settings panel is hardcoded in terms of words/description, except for the content.

One way would be to write a plugin that overwrites settings function. This would require re-writing the whole settings function in the plugin and displaying it again (with the actual plugin). In terms of the future, I would be happy with having 100 different plugins, each plugin for its own language.

AndiLeni commented 7 years ago

Unfortunately, I have to admit that my knowledge is not enough to tackle this project. In my computer science studies I am still at the beginning. But I would help if it should come to an implementation.

robiso commented 7 years ago

I don't think that's a problem, we can add it to the "roadmap" I'm sure someone will tackle this issue further down the road.

In the mean time, could you give this 2.3.2 (test version) index.php a drive? https://github.com/robiso/WonderCMS-testRepo

AndiLeni commented 7 years ago

I tested the version and found no problems. No error messages and no problems during usage.

robiso commented 7 years ago

Thank you @AndiLeni. Preparing for 2.3.2 roll out in the upcoming days.

PiersMorgan commented 6 years ago

I believe i have come up for a solution to this using PHP. The code will detect the language, validate it and then depending on the language redirect to the correct admin page, e.g /admin_es /admin_de etc

The PHP code is a few lines and i have placed it within the index.php for now, but can easily be ported to a plugin which when uploaded includes this piece of code. I might also enhance this further so when the plugin is uploaded it places a little dropdown in the navbar for the user to select the language and then it will convert all text on the site.

Note: The sweet thing is this could also be used site wide to translate the entire CMS :)

RarogCmex commented 5 years ago

Language support must be an very good feature, I think. May be we should add an a category languages such as plugins/themes categories.

StephanStanisic commented 5 years ago

I'd vote for a solution that uses a plugin to supply language files. Have some special handling in the core, but let plugins "hook" language files to the core.

Something like:

plugins/
    language-nl_NL/
        nl_NL.csv
        language-nl_NL.php

And letting the plugin pass a dictionary of translations to the core.

StephanStanisic commented 4 years ago

Some time ago this maybe a bit tricky but plausible idea popped in my head. A lot of translations are in a preg_replace format. What if we just preg_replace the admin html?

So behold: here is a really simple solution to the translation issue.

Add a lot of preg_replace-style translations in a csv (most CMSes I've tried used this format, so that's why I did it too) and just looping over them. Thats it.

Here is a repo with the admin html translated to Dutch: https://github.com/StephanStanisic/zlanguage-nl_NL

It isn't the nicest solution, but by prepending every preg_replace with the end of the tag, we assure that only the contents of the tag are replaced, and not other things.

More on how the csv is created in the README of the repo.

I still think that translations is something that should be the task of the CMS, and that plugins could deliver the language files. But this method gives us a easy solution for the time being.

RarogCmex commented 4 years ago

Experimental Russian translation based on yours. Currently I can't test it because my server is awaiting to bay ^), so I'll test it after another week or two. https://github.com/RarogCmex/zlanguage-ru_RU

StephanStanisic commented 4 years ago

Looks awesome! I found some issues and have opened an PR!

RarogCmex commented 4 years ago

Looks awesome! I found some issues and have opened an PR! image

Thank you, now I confirm it's works. There are some untransleted words however, but I'm not going to do it todays. To do next, translate plugins such as simple blog.

RarogCmex commented 4 years ago

I've just updated https://github.com/RarogCmex/zlanguage-ru_RU with translating everything that I can @StephanStanisic You may use it as template

robiso commented 4 years ago

@StephanStanisic @RarogCmex I've prepared an updated version for the updated/upcoming WonderCMS release: https://github.com/robiso/translation-slovenian

Note: this probably wont fully work with your current versions, but in the upcoming 3.0.8 version it's the full thing.

Love your effort, thank you for creating this @StephanStanisic. Also thanks for your contribution @RarogCmex 🚀

robiso commented 4 years ago

Closing this issue (after 3 years) since we now have language plugins. Thank you @StephanStanisic!