diff --git a/README.en.md b/README.en.md index f1363ba..7bcd5bc 100644 --- a/README.en.md +++ b/README.en.md @@ -86,6 +86,7 @@ SITE_URL=http://localhost DNS_SERVERS=1.1.1.1, 8.8.8.8 DEBUG=true SELENIUM_HOST=selenium-hub:4444 +LANGUAGE=pt-br ``` 4. Run everything: @@ -105,7 +106,10 @@ The configurations are organized in `data/`: - `global_rules.php`: Rules that apply to all sites - `blocked_domains.php`: List of blocked sites - `user_agents.php`: User Agents configurations -- `messages.php`: System messages + +### Translations + +- `/languages/`: Each language is in its ISO id (`pt-br, en or es`) and can be defined in the `LANGUAGE` environment ### S3 Cache diff --git a/README.md b/README.md index 67af8e6..e810a7e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ SITE_URL=http://localhost DNS_SERVERS=1.1.1.1, 8.8.8.8 DEBUG=true SELENIUM_HOST=selenium-hub:4444 +LANGUAGE=pt-br ``` 4. Roda tudo: @@ -105,7 +106,10 @@ As configurações estão organizadas em `data/`: - `global_rules.php`: Regras que se aplicam a todos os sites - `blocked_domains.php`: Lista de sites bloqueados - `user_agents.php`: Configurações de User Agents -- `messages.php`: Mensagens do sistema + +### Traduções + +- `/languages/`: Cada lingua está em seu ISO id (`pt-br, en ou es`) e pode ser definida no environment `LANGUAGE` ### Cache S3 diff --git a/app/.env.sample b/app/.env.sample index e4e99df..8b33b99 100644 --- a/app/.env.sample +++ b/app/.env.sample @@ -7,6 +7,12 @@ SITE_NAME=Marreta # Descrição do site usada em meta tags e SEO SITE_DESCRIPTION="Chapéu de paywall é marreta!" +# Idioma do site (opções disponíveis: pt-br, en, es) +# pt-br = Português do Brasil +# en = English +# es = Español +LANGUAGE=pt-br + # URL base do site (sem barra no final) # Use https://localhost para desenvolvimento local SITE_URL=https://localhost diff --git a/app/config.php b/app/config.php index f33a2b1..5c23bfc 100644 --- a/app/config.php +++ b/app/config.php @@ -7,7 +7,6 @@ * - Carregamento de variáveis de ambiente * - Definições de constantes do sistema * - Configurações de segurança - * - Mensagens do sistema * - Configurações de bots e user agents * - Lista de domínios bloqueados * - Configurações de cache S3 @@ -30,6 +29,7 @@ define('DISABLE_CACHE', isset($_ENV['DISABLE_CACHE']) ? filter_var($_ENV['DISABL define('SELENIUM_HOST', isset($_ENV['SELENIUM_HOST']) ? $_ENV['SELENIUM_HOST'] : 'localhost:4444'); define('CACHE_DIR', __DIR__ . '/cache'); define('DEBUG', isset($_ENV['DEBUG']) ? filter_var($_ENV['DEBUG'], FILTER_VALIDATE_BOOLEAN) : false); +define('LANGUAGE', isset($_ENV['LANGUAGE']) ? $_ENV['LANGUAGE'] : 'pt-br'); /** * Configurações de Redis @@ -60,7 +60,6 @@ if (S3_CACHE_ENABLED) { /** * Carrega as configurações do sistema */ -define('MESSAGES', require __DIR__ . '/data/messages.php'); define('USER_AGENTS', require __DIR__ . '/data/user_agents.php'); define('BLOCKED_DOMAINS', require __DIR__ . '/data/blocked_domains.php'); define('DOMAIN_RULES', require __DIR__ . '/data/domain_rules.php'); diff --git a/app/data/messages.php b/app/data/messages.php deleted file mode 100644 index 4f993b2..0000000 --- a/app/data/messages.php +++ /dev/null @@ -1,42 +0,0 @@ - [ - 'message' => 'Este domínio está bloqueado para extração.', - 'type' => 'error' - ], - 'DNS_FAILURE' => [ - 'message' => 'Falha ao resolver DNS para o domínio. Verifique se a URL está correta.', - 'type' => 'warning' - ], - 'HTTP_ERROR' => [ - 'message' => 'O servidor retornou um erro ao tentar acessar a página. Tente novamente mais tarde.', - 'type' => 'warning' - ], - 'CONNECTION_ERROR' => [ - 'message' => 'Erro ao conectar com o servidor. Verifique sua conexão e tente novamente.', - 'type' => 'warning' - ], - 'CONTENT_ERROR' => [ - 'message' => 'Não foi possível obter o conteúdo. Tente usar os serviços de arquivo.', - 'type' => 'warning' - ], - 'INVALID_URL' => [ - 'message' => 'Formato de URL inválido', - 'type' => 'error' - ], - 'NOT_FOUND' => [ - 'message' => 'Página não encontrada', - 'type' => 'error' - ], - 'GENERIC_ERROR' => [ - 'message' => 'Ocorreu um erro ao processar sua solicitação.', - 'type' => 'warning' - ] -]; diff --git a/app/inc/Language.php b/app/inc/Language.php new file mode 100644 index 0000000..d571a41 --- /dev/null +++ b/app/inc/Language.php @@ -0,0 +1,34 @@ + 'Unknown message', + 'type' => 'error' + ]; + } + + public static function getCurrentLanguage() { + return self::$currentLanguage; + } +} \ No newline at end of file diff --git a/app/index.php b/app/index.php index 66599cb..3bb0802 100644 --- a/app/index.php +++ b/app/index.php @@ -13,6 +13,10 @@ require_once 'config.php'; require_once 'inc/Cache.php'; +require_once 'inc/Language.php'; + +// Initialize language +Language::init(LANGUAGE); // Inicialização de variáveis $message = ''; @@ -20,10 +24,11 @@ $message_type = ''; $url = ''; // Processa mensagens de erro/alerta da query string -if (isset($_GET['message']) && isset(MESSAGES[$_GET['message']])) { +if (isset($_GET['message'])) { $message_key = $_GET['message']; - $message = MESSAGES[$message_key]['message']; - $message_type = MESSAGES[$message_key]['type']; + $messageData = Language::getMessage($message_key); + $message = $messageData['message']; + $message_type = $messageData['type']; } // Processa submissão do formulário @@ -33,8 +38,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['url'])) { header('Location: ' . SITE_URL . '/p/' . urlencode($url)); exit; } else { - $message = MESSAGES['INVALID_URL']['message']; - $message_type = MESSAGES['INVALID_URL']['type']; + $messageData = Language::getMessage('INVALID_URL'); + $message = $messageData['message']; + $message_type = $messageData['type']; } } @@ -43,7 +49,7 @@ $cache = new Cache(); $cache_folder = $cache->getCacheFileCount(); ?> - + @@ -61,19 +67,19 @@ $cache_folder = $cache->getCacheFileCount();
-
-

- Marreta - -

-

-

- - - - paredes derrubadas! -

-
+
+

+ Marreta + +

+

+

+ + + + +

+
@@ -87,16 +93,16 @@ $cache_folder = $cache->getCacheFileCount(); name="url" id="url" class="flex-1 block w-full rounded-none rounded-r-lg text-lg py-4 border border-l-0 border-gray-300 bg-gray-50 focus:border-blue-500 focus:ring-blue-500 shadow-sm bg-gray-50" - placeholder="Digite a URL (ex: https://exemplo.com)" + placeholder="" value="" required pattern="https?://.+" - title="Por favor, insira uma URL válida começando com http:// ou https://"> + title="">
@@ -126,7 +132,7 @@ $cache_folder = $cache->getCacheFileCount();

Acesso direito - Acesso direto: +

/p/https://exemplo.com

@@ -135,18 +141,18 @@ $cache_folder = $cache->getCacheFileCount();

Favoritos - Adicione aos Favoritos +

- Arraste o botão abaixo para sua barra de favoritos para acessar o rapidamente em qualquer página: +

@@ -156,7 +162,7 @@ $cache_folder = $cache->getCacheFileCount();

Serviços alternativos - Serviços alternativos +

getCacheFileCount(); diff --git a/app/languages/en.php b/app/languages/en.php new file mode 100644 index 0000000..b891b9c --- /dev/null +++ b/app/languages/en.php @@ -0,0 +1,55 @@ + 'Paywall hat is a sledgehammer!', + 'walls_destroyed' => 'walls destroyed!', + 'url_placeholder' => 'Enter URL (e.g., https://example.com)', + 'analyze_button' => 'Analyze', + 'direct_access' => 'Direct access:', + 'bookmarklet_title' => 'Add to Bookmarks', + 'bookmarklet_description' => 'Drag the button below to your bookmarks bar to quickly access {site_name} on any page:', + 'open_in' => 'Open in {site_name}', + 'alternative_services' => 'Alternative Services', + 'api_title' => 'REST API', + 'api_description' => '{site_name} provides a REST API for integration with other systems:', + 'endpoint' => 'Endpoint:', + 'success_response' => 'Success response:', + 'error_response' => 'Error response:', + 'open_source_title' => 'Open Source Project', + 'open_source_description' => 'This is an open source project made with ❤️!
You can contribute, report issues, or make suggestions through GitHub.', + + 'messages' => [ + 'BLOCKED_DOMAIN' => [ + 'message' => 'This domain is blocked for extraction.', + 'type' => 'error' + ], + 'DNS_FAILURE' => [ + 'message' => 'Failed to resolve DNS for the domain. Please verify if the URL is correct.', + 'type' => 'warning' + ], + 'HTTP_ERROR' => [ + 'message' => 'The server returned an error while trying to access the page. Please try again later.', + 'type' => 'warning' + ], + 'CONNECTION_ERROR' => [ + 'message' => 'Error connecting to the server. Check your connection and try again.', + 'type' => 'warning' + ], + 'CONTENT_ERROR' => [ + 'message' => 'Could not get content. Try using archive services.', + 'type' => 'warning' + ], + 'INVALID_URL' => [ + 'message' => 'Invalid URL format', + 'type' => 'error' + ], + 'NOT_FOUND' => [ + 'message' => 'Page not found', + 'type' => 'error' + ], + 'GENERIC_ERROR' => [ + 'message' => 'An error occurred while processing your request.', + 'type' => 'warning' + ] + ] +]; \ No newline at end of file diff --git a/app/languages/es.php b/app/languages/es.php new file mode 100644 index 0000000..e0656c5 --- /dev/null +++ b/app/languages/es.php @@ -0,0 +1,55 @@ + '¡El sombrero del muro de pago es un martillo!', + 'walls_destroyed' => '¡paredes destruidas!', + 'url_placeholder' => 'Ingrese URL (ej: https://ejemplo.com)', + 'analyze_button' => 'Analizar', + 'direct_access' => 'Acceso directo:', + 'bookmarklet_title' => 'Agregar a Favoritos', + 'bookmarklet_description' => 'Arrastra el botón a tu barra de favoritos para acceder rápidamente a {site_name} en cualquier página:', + 'open_in' => 'Abrir en {site_name}', + 'alternative_services' => 'Servicios Alternativos', + 'api_title' => 'API REST', + 'api_description' => '{site_name} proporciona una API REST para integración con otros sistemas:', + 'endpoint' => 'Endpoint:', + 'success_response' => 'Respuesta exitosa:', + 'error_response' => 'Respuesta de error:', + 'open_source_title' => 'Proyecto de Código Abierto', + 'open_source_description' => '¡Este es un proyecto de código abierto hecho con ❤️!
Puedes contribuir, reportar problemas o hacer sugerencias a través de GitHub.', + + 'messages' => [ + 'BLOCKED_DOMAIN' => [ + 'message' => 'Este dominio está bloqueado para extracción.', + 'type' => 'error' + ], + 'DNS_FAILURE' => [ + 'message' => 'Error al resolver DNS para el dominio. Verifique si la URL es correcta.', + 'type' => 'warning' + ], + 'HTTP_ERROR' => [ + 'message' => 'El servidor devolvió un error al intentar acceder a la página. Por favor, inténtelo más tarde.', + 'type' => 'warning' + ], + 'CONNECTION_ERROR' => [ + 'message' => 'Error al conectar con el servidor. Verifique su conexión e inténtelo de nuevo.', + 'type' => 'warning' + ], + 'CONTENT_ERROR' => [ + 'message' => 'No se pudo obtener el contenido. Intente usar los servicios de archivo.', + 'type' => 'warning' + ], + 'INVALID_URL' => [ + 'message' => 'Formato de URL inválido', + 'type' => 'error' + ], + 'NOT_FOUND' => [ + 'message' => 'Página no encontrada', + 'type' => 'error' + ], + 'GENERIC_ERROR' => [ + 'message' => 'Ocurrió un error al procesar su solicitud.', + 'type' => 'warning' + ] + ] +]; \ No newline at end of file diff --git a/app/languages/pt-br.php b/app/languages/pt-br.php new file mode 100644 index 0000000..2f65214 --- /dev/null +++ b/app/languages/pt-br.php @@ -0,0 +1,54 @@ + 'paredes derrubadas!', + 'url_placeholder' => 'Digite a URL (ex: https://exemplo.com)', + 'analyze_button' => 'Analisar', + 'direct_access' => 'Acesso direto:', + 'bookmarklet_title' => 'Adicione aos Favoritos', + 'bookmarklet_description' => 'Arraste o botão abaixo para sua barra de favoritos para acessar o {site_name} rapidamente em qualquer página:', + 'open_in' => 'Abrir no {site_name}', + 'alternative_services' => 'Serviços alternativos', + 'api_title' => 'API REST', + 'api_description' => 'O {site_name} disponibiliza uma API REST para integração com outros sistemas:', + 'endpoint' => 'Endpoint:', + 'success_response' => 'Resposta de sucesso:', + 'error_response' => 'Resposta de erro:', + 'open_source_title' => 'Projeto Open Source', + 'open_source_description' => 'Este é um projeto de código aberto feito com ❤️!
Você pode contribuir, reportar problemas ou fazer sugestões através do GitHub.', + + 'messages' => [ + 'BLOCKED_DOMAIN' => [ + 'message' => 'Este domínio está bloqueado para extração.', + 'type' => 'error' + ], + 'DNS_FAILURE' => [ + 'message' => 'Falha ao resolver DNS para o domínio. Verifique se a URL está correta.', + 'type' => 'warning' + ], + 'HTTP_ERROR' => [ + 'message' => 'O servidor retornou um erro ao tentar acessar a página. Tente novamente mais tarde.', + 'type' => 'warning' + ], + 'CONNECTION_ERROR' => [ + 'message' => 'Erro ao conectar com o servidor. Verifique sua conexão e tente novamente.', + 'type' => 'warning' + ], + 'CONTENT_ERROR' => [ + 'message' => 'Não foi possível obter o conteúdo. Tente usar os serviços de arquivo.', + 'type' => 'warning' + ], + 'INVALID_URL' => [ + 'message' => 'Formato de URL inválido', + 'type' => 'error' + ], + 'NOT_FOUND' => [ + 'message' => 'Página não encontrada', + 'type' => 'error' + ], + 'GENERIC_ERROR' => [ + 'message' => 'Ocorreu um erro ao processar sua solicitação.', + 'type' => 'warning' + ] + ] +]; \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 1aca2d5..c9c5e1a 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -48,6 +48,10 @@ if [ -n "${SITE_URL}" ]; then echo "SITE_URL=${SITE_URL}" >> /app/.env fi +if [ -n "${LANGUAGE}" ]; then + echo "LANGUAGE=${LANGUAGE}" >> /app/.env +fi + if [ -n "${DNS_SERVERS}" ]; then echo "DNS_SERVERS=${DNS_SERVERS}" >> /app/.env fi