cachethq / core

🚦 The core of Cachet, the open-source status page system.
https://cachethq.io
MIT License
101 stars 20 forks source link

Translations #21

Closed jbrooksuk closed 5 months ago

jbrooksuk commented 9 months ago

We need to provide any static strings as a translation file.

I'm quite keen on the idea of this package only containing the English US translations, then having other packages which can be installed to provide additional languages. Are there any objections to this?

alexjustesen commented 9 months ago

What are you're thoughts on using https://crowdin.com/ to manage translations?

Really excited this project is back btw. Happy to help contribute.

jbrooksuk commented 9 months ago

Yep, we previously used CrowdIn and I think we'll continue to do so.

jbrooksuk commented 9 months ago

We'll also want to make sure the frontend is translated in the dashboard too.

jbrooksuk commented 5 months ago

https://github.com/cachethq/core/commit/fbdf8dd5ffa7ff6de98204b31515a43434b5bb5d

jbrooksuk commented 5 months ago

For my own memory, I wrote this quick Python script to pull all strings within __ and print them out in a JSON object:

import re
import os
import json

def find_translation_strings(directories, file_extensions):
    translation_strings = {}
    regex_pattern = re.compile(r"__\('(.+?)'\)")

    for directory in directories:
        for root, dirs, files in os.walk(directory):
            for file in files:
                if any(file.endswith(ext) for ext in file_extensions):
                    with open(os.path.join(root, file), 'r') as f:
                        content = f.read()
                        matches = regex_pattern.findall(content)
                        for match in matches:
                            translation_strings[match] = match

    sorted_translation_strings = dict(sorted(translation_strings.items()))
    return json.dumps(sorted_translation_strings, indent=4)

directories = ['src', 'resources/views']
file_extensions = ['.php', '.blade.php']
translation_strings = find_translation_strings(directories, file_extensions)
print(translation_strings)