Skip to content

Instantly share code, notes, and snippets.

@ManotLuijiu
Last active March 21, 2025 06:51
Show Gist options
  • Save ManotLuijiu/ac3ecbc8981ed5f7fdd2319694731ed8 to your computer and use it in GitHub Desktop.
Save ManotLuijiu/ac3ecbc8981ed5f7fdd2319694731ed8 to your computer and use it in GitHub Desktop.
Systemd script for automate translation in Frappe/ERPNext
[Unit]
Description=ERPNext Thai Business Suite Translation Updater
After=network.target
[Service]
Type=oneshot
User=frappe
Group=frappe
WorkingDirectory=/home/frappe/moo-bench
ExecStart=/bin/bash -c '/usr/local/bin/bench update-po-files --app thai_business_suite && /usr/local/bin/bench compile-po-to-mo --app>
Restart=no
[Install]
WantedBy=multi-user.target
[Unit]
Description=Run ERPNext Thai Business Suite Translation Updater daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
#!/bin/bash
# Set up translation service files and enable them
# Default values
FRAPPE_USER="frappe"
BENCH_PATH="frappe-bench"
APP_NAME="erpnext"
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo"
exit 1
fi
# Get custom values if provided
read -p "Enter Frappe user name [$FRAPPE_USER]: " input_user
FRAPPE_USER=${input_user:-$FRAPPE_USER}
read -p "Enter bench directory name [$BENCH_PATH]: " input_bench
BENCH_PATH=${input_bench:-$BENCH_PATH}
read -p "Enter app name [$APP_NAME]: " input_app
APP_NAME=${input_app:-$APP_NAME}
FULL_PATH="/home/$FRAPPE_USER/$BENCH_PATH"
echo "Setting up with the following configuration:"
echo "Frappe User: $FRAPPE_USER"
echo "Bench Path: $FULL_PATH"
echo "App Name: $APP_NAME"
echo ""
# Step 1: Create the service file
cat > /etc/systemd/system/erpnext-translation.service << EOF
[Unit]
Description=Frappe/ERPNext $APP_NAME Translation Updater
After=network.target
[Service]
Type=oneshot
User=$FRAPPE_USER
Group=$FRAPPE_USER
WorkingDirectory=$FULL_PATH
ExecStart=/bin/bash -c '/usr/local/bin/bench update-po-files --app $APP_NAME && /usr/local/bin/bench compile-po-to-mo --app $APP_NAME'
Restart=no
[Install]
WantedBy=multi-user.target
EOF
echo "Service file created."
# Step 2: Create the timer file
cat > /etc/systemd/system/erpnext-translation.timer << 'EOF'
[Unit]
Description=Run Frappe/ERPNext $APP_NAME Translation Updater daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
echo "Timer file created."
# Step 3 & 4: Enable and start timer and service
systemctl daemon-reload
systemctl enable erpnext-translation.timer
systemctl start erpnext-translation.timer
systemctl enable erpnext-translation.service
echo "Services enabled and started."
# Step 5: Verify status
echo "Checking service status..."
systemctl status erpnext-translation.service
echo "Checking timer status..."
systemctl status erpnext-translation.timer
echo "Setup complete!"
@ManotLuijiu
Copy link
Author

ManotLuijiu commented Mar 21, 2025

ERPNext Thai Translation Automation

This guide explains how to set up automatic translation updates for Thai language in ERPNext.

Automated Setup

Using Bash Script

  1. Save the bash script to a file named setup-translation-service.sh in your home folder:

    curl -o ~/setup-translation-service.sh https://gist.githubusercontent.com/ManotLuijiu/ac3ecbc8981ed5f7fdd2319694731ed8/raw/65525574c323d7b83761d73e7c35e0d3ec422f64/setup-translation-service.sh
  2. Make it executable:

    chmod +x ~/setup-translation-service.sh

or 1 + 2

curl -o ~/setup-translation-service.sh https://gist.githubusercontent.com/ManotLuijiu/ac3ecbc8981ed5f7fdd2319694731ed8/raw/65525574c323d7b83761d73e7c35e0d3ec422f64/setup-translation-service.sh && chmod +x ~/setup-translation-service.sh
  1. Run it with sudo:

    sudo ./setup-translation-service.sh
  2. Follow the prompts to customize the values if needed.

Manual Setup

Create 2 files:

  1. Create the service file:

    sudo nano /etc/systemd/system/erpnext-translation.service

    Add the following content:
    Suppose your frappe folder is '/home/frappe/frappe-bench' and
    your app name is thai_business_suite

    [Unit]
    Description=ERPNext Thai Business Suite Translation Updater
    After=network.target
    
    [Service]
    Type=oneshot
    User=frappe
    Group=frappe
    WorkingDirectory=/home/frappe/frappe-bench
    ExecStart=/bin/bash -c '/usr/local/bin/bench update-po-files --app thai_business_suite && /usr/local/bin/bench compile-po-to-mo --app thai_business_suite'
    Restart=no
    
    [Install]
    WantedBy=multi-user.target
    
  2. Create the timer file:

    sudo nano /etc/systemd/system/erpnext-translation.timer

    Add the following content:

    [Unit]
    Description=Run ERPNext Thai Business Suite Translation Updater daily
    
    [Timer]
    OnCalendar=daily
    Persistent=true
    
    [Install]
    WantedBy=timers.target
    
  3. Enable and start the services:

    sudo systemctl daemon-reload
    sudo systemctl enable erpnext-translation.timer
    sudo systemctl start erpnext-translation.timer
    sudo systemctl enable erpnext-translation.service

Verifying the Status

Check the service status:

sudo systemctl status erpnext-translation

Example output:

○ erpnext-translation.service - ERPNext Thai Business Suite Translation Updater
     Loaded: loaded (/etc/systemd/system/erpnext-translation.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2025-03-21 01:24:44 +07; 10h ago
TriggeredBy: ● erpnext-translation.timer
    Process: 34491 ExecStart=/bin/bash -c /usr/local/bin/bench update-po-files --app thai_business_suite && /usr/local/bin/bench compile-po-to-mo --app thai_business_suite (code=exited, status=0/SUCCESS)
   Main PID: 34491 (code=exited, status=0/SUCCESS)
        CPU: 3.079s

Mar 21 01:24:41 ubuntu-8gb-hel1-1-ERPNext-Dev systemd[1]: Starting ERPNext Thai Business Suite Translation Updater...
Mar 21 01:24:42 ubuntu-8gb-hel1-1-ERPNext-Dev bash[34492]: PO file modified at /home/frappe/moo-bench/apps/thai_business_suite/thai_business_suite/locale/th.po
Mar 21 01:24:44 ubuntu-8gb-hel1-1-ERPNext-Dev bash[34524]: MO file created at /home/frappe/moo-bench/sites/assets/locale/th/LC_MESSAGES/thai_business_suite.mo
Mar 21 01:24:44 ubuntu-8gb-hel1-1-ERPNext-Dev systemd[1]: erpnext-translation.service: Deactivated successfully.
Mar 21 01:24:44 ubuntu-8gb-hel1-1-ERPNext-Dev systemd[1]: Finished ERPNext Thai Business Suite Translation Updater.
Mar 21 01:24:44 ubuntu-8gb-hel1-1-ERPNext-Dev systemd[1]: erpnext-translation.service: Consumed 3.079s CPU time.

This status indicates that the translation service is working correctly and has successfully updated the translation files.

What This Does

The service will:

  1. Update the PO files with any new translatable strings from your code
  2. Compile the PO files to binary MO files used by the application
  3. Run daily to keep translations up to date as your code evolves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment