Skip to content

Commit

Permalink
feat (EFDE): #32 translations system
Browse files Browse the repository at this point in the history
- Add feature to incorporate translation into i18n directory
  - en_US
  - es_ES
  - pt_PT
- Translations of implementations available so far
- Fix small bugs
  • Loading branch information
mmaximo33 committed May 11, 2024
1 parent 6b54191 commit 1b30b63
Show file tree
Hide file tree
Showing 30 changed files with 420 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.2.0] 2024-xx-xx

### Added

- EFDE: #32 Translation system (en_US es_ES pt_PT)
- Laravel: #5 Add new implemention
- Wordpress: #31 Add new implemention
- Symfony: #35 Add new version of Symfony 7.x
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
![pull-open](https://img.shields.io/github/issues-pr/mmaximo33/efde.svg)
![pull-close](https://img.shields.io/github/issues-pr-closed/mmaximo33/efde.svg)

![efde version](https://img.shields.io/badge/language-grey.svg) ![en_US](https://img.shields.io/badge/en.US-blue.svg) ![es_ES](https://img.shields.io/badge/es.ES-blue.svg) ![pt_PT](https://img.shields.io/badge/pt.PT-blue.svg)

## Index

- [Intro](#intro)
Expand Down
19 changes: 15 additions & 4 deletions bin/efde.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
set -euo pipefail

declare -gA GLOBAL_EFDE_CONFIG=(
[EFDE_MODE_DEBUG]=false # Debug Messages
[EFDE_MODE_DEVELOP]=false # MMTodo: Prepared for create tmps
[LANGUAGE_DEFAULT]="en_US"
[EFDE_MODE_DEBUG]=false # Debug Messages
[EFDE_MODE_DEVELOP]=false # MMTodo: Prepared for create tmps
)

resolve_absolute_dir() {
Expand Down Expand Up @@ -38,8 +39,18 @@ menu_implementation(){
fi
}

menu(){
generate_extra_elements(){
efde.tasks.config.check_config
common.core.generate_shortcuts_file

if [ "${GLOBAL_EFDE_CONFIG['EFDE_MODE_DEBUG']}" = "true" ]; then
if [ ${GLOBAL_EFDE_CONFIG['LANGUAGE_DEFAULT']} != "$(efde.tasks.config.get_var "EFDE_LANGUAGE")" ]; then
common.core.generate_transactions
fi
fi
}

menu(){
if ! efde.tasks.implemention.has_folder_implementation ; then
efde.tasks.menu.main
fi
Expand All @@ -48,12 +59,12 @@ menu(){
}

shortcuts(){
efde.tasks.config.check_config
common.tasks.shortcuts.target "$@"
}

main() {
init_dirs # IMPORTANT
generate_extra_elements
if [ $# -gt 0 ]; then
shortcuts "$@"
else
Expand Down
47 changes: 43 additions & 4 deletions console/common/core
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail

_mod_.step(){
_mod_.msg_debug "#######################################################################"
_mod_.msg_debug "# LOAD MODULES "
_mod_.msg_debug "# LOAD $1 "
_mod_.msg_debug "-----------------------------------------------------------------------"
}

Expand Down Expand Up @@ -57,7 +57,7 @@ _mod_.load_module(){
local MODULE_NAME=$(basename "$PATH_MODULE")

local elements=("props" "tasks")
_mod_.step
_mod_.step "MODULES"
_mod_.msg_debug "Module: $MODULE_NAME" 1

for element in "${elements[@]}"; do
Expand Down Expand Up @@ -116,6 +116,10 @@ _mod_.replacemod () {
sed -E "s/_mod_([a-zA-Z_][a-zA-Z0-9_]*)/${NEW_NAME_VAR}_\1/g" "$SOURCE_PATH" > "$PATH_TARGET"
fi

# translation
#sed -i "s/Select an option/hola/g" "$PATH_TARGET"


if [ ! $? -eq 0 ]; then
_mod_.msg_danger "[ERROR] The conversion could not be carried out, report this!" 4
_mod_.msg_danger "Source: $SOURCE_PATH" 5
Expand All @@ -133,7 +137,6 @@ _mod_.replacemod () {
fi
}

# Función para extraer valores
_mod_.generate_shortcuts_file() {
local TARGET_SHORTCUTS="$DIRECTORY_TMP/common.props.shortcuts"

Expand All @@ -157,8 +160,44 @@ _mod_.generate_shortcuts_file() {
echo ")" >> "$TARGET_SHORTCUTS"

source $TARGET_SHORTCUTS
_mod_.step "SHORTCUTS"
_mod_.msg_debug "Shortcuts file created in $TARGET_SHORTCUTS"
}


# MMTodo:
# Improve this feature so that
# - Take all characters enclosed in double quotes (\n or \")
# - Do not consider spaces between origin and destination ("origin", "destination")
_mod_.generate_transactions(){
local PATH_TO_INSPECT="${1:-$PATH_CONSOLE}"
local LANGUAGE_DEFAULT=${GLOBAL_EFDE_CONFIG['LANGUAGE_DEFAULT']}
local LANGUAGE_CONFIG=$(efde.tasks.config.get_var "EFDE_LANGUAGE")
if [ "$LANGUAGE_DEFAULT" != "$LANGUAGE_CONFIG" ]; then
DIRECTORIES=$(find "$PATH_TO_INSPECT" -maxdepth 1 -type d ! -path "$PATH_TO_INSPECT" ! -name "$(basename "$PATH_TO_INSPECT")" -printf "%f\n")
for DIRECTORY in $DIRECTORIES; do

local PATH_TARGET="$PATH_TO_INSPECT/$DIRECTORY"
local PATH_TASKS_EXISTS="$PATH_TARGET/tasks"

if [ ! -d "$PATH_TASKS_EXISTS" ]; then
_mod_.generate_transactions "$PATH_TARGET"
else
local FILE_i18n="$PATH_TARGET/i18n/$LANGUAGE_CONFIG"
if common.tasks.file.exists "$FILE_i18n"; then
while IFS= read -r line || [ -n "$line" ]; do
[ -z "$line" ] && continue

line=$(echo "$line" | sed 's/^"//; s/"$//')
text_old=$(echo "$line" | awk -F '","' '{print $1}')
text_new=$(echo "$line" | awk -F '","' '{print $2}')

if [ -n "$text_old" ] && [ -n "$text_new" ]; then
find "$DIRECTORY_TMP" -type f -name "$DIRECTORY.*" -exec sh -c "sed -i 's#$text_old#$text_new#g' {};" \;
fi
done < "$FILE_i18n"
fi
fi
done
fi
}

14 changes: 14 additions & 0 deletions console/common/i18n/es_ES
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"Select an option","Seleccione una opción"
"Error: Path '$PATH' does not exist.","Error: El path '$PATH' no existe."
"Delete FOLDER","Eliminar DIRECTORIO"
"Confirm this action by writing '$CONFIRM_COLOR':","Confirme esta accion escribiendo '$CONFIRM_COLOR':"
"We are about to delete the directory","Estamos a punto de eliminar el directorio"
"We are about to delete the file","Estamos a punto de eliminar el archivo"
"Removed: $PATH","Eliminado: $PATH"
"Removal aborted.","Eliminación cancelada."
"Enter the url of your repository\nEnter URL (https):","Ingrese la url de su repositorio\nIngresar URL (https):"
"Press R to return | Q to quit | I for info","Presionar R para volver | Q para salir | I mas informacion"
"Enter the option number:","Ingresar numero de opción:"
"The '$choice' option is not in the list.","La opción '$choice' no esta en la lista."
"But we found some that may match the desired action:","Pero encontramos algunos que podrian coincidir con la action:"
"The shortcut is not registered:","El shortcut no esta registrado:"
14 changes: 14 additions & 0 deletions console/common/i18n/pt_PT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"Select an option","Selecione uma opção"
"Error: Path '$PATH' does not exist.","Erro: O caminho '$PATH' não existe."
"Delete FOLDER","Excluir PASTA"
"Confirm this action by writing '$CONFIRM_COLOR':","Confirme esta ação escrevendo '$CONFIRM_COLOR':"
"We are about to delete the directory","Estamos prestes a excluir o diretório"
"We are about to delete the file","Estamos prestes a excluir o arquivo"
"Removed: $PATH","Removido: $PATH"
"Removal aborted.","Remoção cancelada."
"Enter the url of your repository\nEnter URL (https):","Digite o URL do seu repositório\nDigite o URL (https):"
"Press R to return | Q to quit | I for info","Pressione R para retornar | Q para sair | I para informações"
"Enter the option number:","Digite o número da opção:"
"The '$choice' option is not in the list.","A opção '$choice' não está na lista."
"But we found some that may match the desired action:","Mas encontramos algumas que podem corresponder à ação desejada:"
"The shortcut is not registered:","O atalho não está registrado:"
22 changes: 11 additions & 11 deletions console/common/tasks/menu
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ declare -gA GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE #VARIABLE GLOBAL - HIGH SOLUTIO

_mod_.msg_debug() {
if [[ "${GLOBAL_EFDE_CONFIG['EFDE_MODE_DEBUG']}" = "true" ]]; then
common.msg_debug "#######################################################################"
common.msg_debug "# MENU "
common.msg_debug "GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE:" 1
common.msg_debug "title: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['title']}" 2
common.msg_debug "description: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['description']}" 2
common.msg_debug "functions:" 2
common.msg_debug "new: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function']}" 3
common.msg_debug "old: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function_old']}" 3 1
common.msg_debug "-----------------------------------------------------------------------"
common.core.msg_debug "#######################################################################"
common.core.msg_debug "# MENU "
common.core.msg_debug "GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE:" 1
common.core.msg_debug "title: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['title']}" 2
common.core.msg_debug "description: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['description']}" 2
common.core.msg_debug "functions:" 2
common.core.msg_debug "new: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function']}" 3
common.core.msg_debug "old: ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function_old']}" 3 1
common.core.msg_debug "-----------------------------------------------------------------------"
fi
}

Expand Down Expand Up @@ -42,7 +42,7 @@ _mod_.print_options(){

printf "%-0s. %-25s %s\n" "$i" "$TITULO" "$DESCRIPTION"
else
common.tasks.message.warning "\nInvalid menu option: Requieres minimum: \"shortcut, function, name\" \n- For: $OPTION"
common.tasks.message.warning "\nInvalid menu option: Requieres minimum: \'shortcut, function, name\' \n- For: $OPTION"
fi
done
}
Expand Down Expand Up @@ -100,7 +100,7 @@ _mod_.chosen_option(){
GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['description']="${VALUES[3]:-${VALUES[2]}}"

else
common.tasks.message.danger "Error: Formato de entrada incorrecto"
common.tasks.message.danger "Error: Incorrect input format"
exit 1
fi
}
Expand Down
37 changes: 37 additions & 0 deletions console/efde/i18n/es_ES
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"Select an option","Seleccione una opción"
"Coming Soon","Proximamente"
"Settings and configurations","Configuraciones"
"Show project EFDE","Ver projecto EFDE"
"Efde Global Settings","Ver configuraciones EFDE"
"Show shortcuts","Mostrar shortcuts"
"Report Bug | Improvements | New Features | others","Reportar bugs | mejoras | nuevas caracteristicas | otros"
"Check update and downloads","Comprobar si existe actualizaciones y descargar"
"Uninstall from computer","Desintalar de mi equipo"
"Set config","Establecer configuraciones"
"Your first time with EFDE?","Tu primera vez con EFDE?"
"We will create the basic configurations","Vamos a crear la configuraciones basicas"
"The translation configuration has been applied, we need to restart EFDE","Se ha aplicado la configuración de traducción, necesitamos reiniciar EFDE"
"Run on your console","Ejecutar en su consola"
"This is your EFDE configuration","Esta es tu configuración de EFDE"
"It is stored in the following file","Se almacena en el siguiente archivo"
"Default language?","Idioma default?"
"Established by implementation","Establecido por la implementación"
"Show executed commands, no output","Mostrar comandos ejecutados, sin salida"
"Show executed commands and output","Mostrar comandos ejecutados y salida"
"Do not show executed commands or output","No mostrar comandos ejecutados o salida"
"select EDITOR default","Seleccionar EDITOR predeterminado"
"The project name already exists in this directory.","El nombre del proyecto ya existe en este directorio."
"Verify","Verificar"
"Enter the project name","Ingresar nombre del proyecto"
"Project name","Nombre del proyecto"
"The entered value can only contain letters or numbers.","El valor ingresado solo puede contener letras o números."
"We are excited about the upcoming release!","¡Estamos entusiasmados con el próximo lanzamiento!"
"Our team is hard at work to bring you the latest features and improvements.","Nuestro equipo está trabajando arduamente para brindarle las últimas funciones y mejoras."
"Stay tuned for updates and follow the projects progress on","Manténgase atento a las actualizaciones y siga el progreso del proyecto en"
"Thank you for your patience, and remember to check back for the latest developments.","Gracias por su paciencia y recuerde volver a consultar las últimas novedades."
"Configuring upstream for branch","Configurando rama principal"
"Up to date!","Actualizado a la fecha!"
"There is an update available!","¡Hay una actualización disponible!"
"Do you want to download the new version?","¿Quieres descargar la nueva versión?"
"Updated!","¡Actualizado!"
"Install for ","Instalación para "
37 changes: 37 additions & 0 deletions console/efde/i18n/pt_PT
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"Select an option","Selecione uma opção"
"Coming Soon","Em breve"
"Settings and configurations","Configurações"
"Show project EFDE","Mostrar projeto EFDE"
"Efde Global Settings","Configurações globais do EFDE"
"Show shortcuts","Mostrar atalhos"
"Report Bug | Improvements | New Features | others","Reportar erro | Melhorias | Novas funcionalidades | outros"
"Check update and downloads","Verificar atualizações e downloads"
"Uninstall from computer","Desinstalar do computador"
"Set config","Configurar"
"Your first time with EFDE?","Sua primeira vez com o EFDE?"
"We will create the basic configurations","Vamos criar as configurações básicas"
"The translation configuration has been applied, we need to restart EFDE","A configuração de tradução foi aplicada, precisamos reiniciar o EFDE"
"Run on your console","Executar no seu console"
"This is your EFDE configuration","Esta é a sua configuração do EFDE"
"It is stored in the following file","Está armazenado no seguinte arquivo"
"Default language?","Idioma padrão?"
"Established by implementation","Estabelecido pela implementação"
"Show executed commands, no output","Mostrar comandos executados, sem saída"
"Show executed commands and output","Mostrar comandos executados e saída"
"Do not show executed commands or output","Não mostrar comandos executados ou saída"
"select EDITOR default","Selecionar EDITOR padrão"
"The project name already exists in this directory.","O nome do projeto já existe neste diretório."
"Verify","Verificar"
"Enter the project name","Digite o nome do projeto"
"Project name","Nome do projeto"
"The entered value can only contain letters or numbers.","O valor inserido só pode conter letras ou números."
"We are excited about the upcoming release!","Estamos animados com o próximo lançamento!"
"Our team is hard at work to bring you the latest features and improvements.","Nossa equipe está trabalhando duro para trazer as últimas funcionalidades e melhorias."
"Stay tuned for updates and follow the projects progress on","Fique ligado para atualizações e acompanhe o progresso do projeto em"
"Thank you for your patience, and remember to check back for the latest developments.","Obrigado pela sua paciência e lembre-se de verificar as últimas novidades."
"Configuring upstream for branch","Configurando upstream para o ramo"
"Up to date!","Atualizado!"
"There is an update available!","Há uma atualização disponível!"
"Do you want to download the new version?","Você quer baixar a nova versão?"
"Updated!","Atualizado!"
"Install for ","Instalar para "
2 changes: 1 addition & 1 deletion console/efde/props/menu
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ set -euo pipefail
)

_mod_CONFIG_SET_LANGUAGE=(
"shortcut:off, es_ES, es_ES, Spanish"
"shortcut:off, en_US, en_US, English"
"shortcut:off, es_ES, es_ES, Spanish"
"shortcut:off, pt_PT, pt_PT, Portuguese"
)
}
29 changes: 20 additions & 9 deletions console/efde/tasks/config
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ _mod_.set_run_cli_efde(){
}

_mod_.check_config() {
_mod_.set_run_cli_efde
if ! common.tasks.file.exists "$CONFIG_PATH_FILE"; then
_mod_.create_config
fi
_mod_.load_config

_mod_.set_run_cli_efde
}

_mod_.create_config() {
common.tasks.message.info "Your first time with EFDE?"
common.tasks.message.info "We will create the basic configurations"
_mod_.set_config


if [ "${GLOBAL_EFDE_CONFIG['LANGUAGE_DEFAULT']}" != "$(efde.tasks.config.get_var "EFDE_LANGUAGE")" ]; then
common.core.generate_transactions
common.tasks.message.info "The translation configuration has been applied, we need to restart EFDE"
common.tasks.message.success "Run on your console \n$ $GLOBAL_RUN_EFDE"
exit # Reload for translations
fi
}

_mod_.set_config(){
Expand Down Expand Up @@ -102,15 +109,19 @@ _mod_.set_config_version() {
}

_mod_.load_config() {
local EFDE_CONFIGS=(
"HOST_SO" "HOST_EDITOR_DEFAULT"
"CLI_DEFAULT" "CLI_SHOW_CLI" "CLI_SHOW_OUTPUT"
"EFDE_MODE_DEBUG" "EFDE_MODE_DEVELOP"
)

for KEY in "${EFDE_CONFIGS[@]}"; do
mapfile -t EFDE_CONFIG < <(grep -o '^[^=]\+' "$CONFIG_PATH_FILE")
for KEY in "${EFDE_CONFIG[@]}"; do
GLOBAL_EFDE_CONFIG["$KEY"]=$(_mod_.get_var "$KEY")
done

if [[ "${GLOBAL_EFDE_CONFIG['EFDE_MODE_DEBUG']}" = "true" ]]; then
common.tasks.message.debug "#######################################################################"
common.tasks.message.debug "# LOAD CONFIG "
common.tasks.message.debug "-----------------------------------------------------------------------"
for clave in "${!GLOBAL_EFDE_CONFIG[@]}"; do
common.tasks.message.tree "$clave: ${GLOBAL_EFDE_CONFIG[$clave]}" 1 0 debug
done
fi
}

_mod_.get_var(){
Expand Down
2 changes: 1 addition & 1 deletion console/efde/tasks/implemention
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ _mod_.project_name(){

if ! [[ "$value" =~ ^[[:alnum:][:space:]]+$ ]]; then
common.tasks.message.danger "The entered value can only contain letters or numbers."
common.tasks.message.info "Cancel to [ctrl + c] "
common.tasks.message.info "Cancel to [ctrl + c]"
_mod_.project_name
fi

Expand Down
4 changes: 2 additions & 2 deletions console/efde/tasks/main
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ set -euo pipefail
}

_mod_.coming_soon(){
common.tasks.message.warning "We're excited about the upcoming release!"
common.tasks.message.warning "We are excited about the upcoming release!"
common.tasks.message.warning "Our team is hard at work to bring you the latest features and improvements."
common.tasks.message.warning "Stay tuned for updates and follow the project's progress on $URL_REPOSITORY."
common.tasks.message.warning "Stay tuned for updates and follow the projects progress on $URL_REPOSITORY."
common.tasks.message.warning "Thank you for your patience, and remember to check back for the latest developments."
}

Expand Down
Loading

0 comments on commit 1b30b63

Please sign in to comment.