Skip to content

Commit b6d2c94

Browse files
silverwindlunnywxiaoguangjolheiser
authored
Improve sed detection in update-locales.sh (#23254)
- ~~Make scripts work from any directory~~ - Detect sed version just like Makefile does --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
1 parent 547c173 commit b6d2c94

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

build/update-locales.sh

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
set -e
4-
5-
SED=sed
3+
# this script runs in alpine image which only has `sh` shell
64

7-
if [[ $OSTYPE == 'darwin'* ]]; then
8-
# for macOS developers, use "brew install gnu-sed"
9-
SED=gsed
5+
set +e
6+
if sed --version 2>/dev/null | grep -q GNU; then
7+
SED_INPLACE="sed -i"
8+
else
9+
SED_INPLACE="sed -i ''"
1010
fi
11+
set -e
1112

1213
if [ ! -f ./options/locale/locale_en-US.ini ]; then
1314
echo "please run this script in the root directory of the project"
@@ -32,7 +33,7 @@ mv ./options/locale/locale_en-US.ini ./options/
3233
# * remove the trailing quote
3334
# * unescape the quotes
3435
# * eg: key="...\"..." => key=..."...
35-
$SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ {
36+
$SED_INPLACE -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ {
3637
s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/
3738
s/"$//
3839
s/\\"/"/g
@@ -41,8 +42,8 @@ $SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ {
4142
# * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks
4243
# * eg: key="... => key=`"...`
4344
# * eg: key=..." => key=`..."`
44-
$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini
45-
$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini
45+
$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini
46+
$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini
4647

4748
# Remove translation under 25% of en_us
4849
baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1)

0 commit comments

Comments
 (0)