Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by MochiMoppel ยป

This is a little coding exercise, inspired by this recent thread.
Below script opens the text file /usr/share/zoneinfo/iso3166.tab, which contains all ISO 3166 country codes, generates associated country flags and feeds the result to gtkdialog.

Not tremendously useful but maybe entertaining and educational. Lots of flags I've never seen - and some countries I've never heard of :oops:
Flags can be enlarged and copied and they are surprisingly detailed, given that they are not images but characters.
The script uses only 1 call to sed and 1 call to gtkdialog, which makes it relatively fast.

The script requires a font containing colored emojis. Works best with NotoColorEmoji.ttf. This font is included in Bookworm64, F96-CE and many other "modern" Puppies.
emojione-android.ttf is a font installed in Fossapup64 9.5. Produces round flags :shock:
TwemojiMozilla.ttf is shipped with *fox browsers but would not work work when copied to the TTF directory. Don't know why.

Code: Select all

#! /bin/bash
## Adds flag glyphs to country codes of text file /usr/share/zoneinfo/iso3166.tab
## Requires font NotoColorEmoji.ttf

function make_flags {
    H='\xf0\x9f\x87\x'          #common hex part of "regional indicators" (first letter A = codepoint 1F1E6 = \xf0\x9f\x87\xa6)
    sed -r "
    /^#/d                               #remove comments
    s/&/&/                          #pangofy ampersands
    s/(..)\t(.*)/\1 <b>\1<\/b> \2/      #duplicate country codes
    s/^A(.*)/${H}a6\1/ ; s/^(.)A(.*)/\1${H}a6\2/
    s/^B(.*)/${H}a7\1/ ; s/^(.)B(.*)/\1${H}a7\2/
    s/^C(.*)/${H}a8\1/ ; s/^(.)C(.*)/\1${H}a8\2/
    s/^D(.*)/${H}a9\1/ ; s/^(.)D(.*)/\1${H}a9\2/
    s/^E(.*)/${H}aa\1/ ; s/^(.)E(.*)/\1${H}aa\2/
    s/^F(.*)/${H}ab\1/ ; s/^(.)F(.*)/\1${H}ab\2/
    s/^G(.*)/${H}ac\1/ ; s/^(.)G(.*)/\1${H}ac\2/
    s/^H(.*)/${H}ad\1/ ; s/^(.)H(.*)/\1${H}ad\2/
    s/^I(.*)/${H}ae\1/ ; s/^(.)I(.*)/\1${H}ae\2/
    s/^J(.*)/${H}af\1/ ; s/^(.)J(.*)/\1${H}af\2/
    s/^K(.*)/${H}b0\1/ ; s/^(.)K(.*)/\1${H}b0\2/
    s/^L(.*)/${H}b1\1/ ; s/^(.)L(.*)/\1${H}b1\2/
    s/^M(.*)/${H}b2\1/ ; s/^(.)M(.*)/\1${H}b2\2/
    s/^N(.*)/${H}b3\1/ ; s/^(.)N(.*)/\1${H}b3\2/
    s/^O(.*)/${H}b4\1/ ; s/^(.)O(.*)/\1${H}b4\2/
    s/^P(.*)/${H}b5\1/ ; s/^(.)P(.*)/\1${H}b5\2/
    s/^Q(.*)/${H}b6\1/ ; s/^(.)Q(.*)/\1${H}b6\2/
    s/^R(.*)/${H}b7\1/ ; s/^(.)R(.*)/\1${H}b7\2/
    s/^S(.*)/${H}b8\1/ ; s/^(.)S(.*)/\1${H}b8\2/
    s/^T(.*)/${H}b9\1/ ; s/^(.)T(.*)/\1${H}b9\2/
    s/^U(.*)/${H}ba\1/ ; s/^(.)U(.*)/\1${H}ba\2/
    s/^V(.*)/${H}bb\1/ ; s/^(.)V(.*)/\1${H}bb\2/
    s/^W(.*)/${H}bc\1/ ; s/^(.)W(.*)/\1${H}bc\2/
    s/^X(.*)/${H}bd\1/ ; s/^(.)X(.*)/\1${H}bd\2/
    s/^Y(.*)/${H}be\1/ ; s/^(.)Y(.*)/\1${H}be\2/
    s/^Z(.*)/${H}bf\1/ ; s/^(.)Z(.*)/\1${H}bf\2/
    s/../<span font=\"$1\">&<\/span>/   #enclose first 2 letters (=flags) in pango span tag
    " /usr/share/zoneinfo/iso3166.tab
}  ;export -f make_flags

export MAIN_DIALOG='<window title="ISO 3166 country codes" allow-shrink="true" width-request="400" height-request="650" window_position="1">
<vbox>
    <vbox scrollable="true">
        <text use-markup="true" xalign="0" wrap="false" selectable="true" can-focus="false">
            <variable export="false">vTEXT</variable>
            <input>make_flags ${vSPIN:-58}</input>
        </text>
    </vbox>
    <hbox>
        <text label="Flag size:"></text>
        <spinbutton space-expand="false"  range-min="10" range-step="8" range-max="200" >
            <variable>vSPIN</variable>
            <default>58</default>
            <action>refresh:vTEXT</action>
        </spinbutton>
        <button label="Close" has-focus="true" width-request="100"></button>
    </hbox>
</vbox>
</window>'

gtkdialog
iso3166flags.png
iso3166flags.png (73 KiB) Viewed 1660 times

[Edit] Clarified font requirements

Last edited by MochiMoppel on Wed Aug 14, 2024 10:49 am, edited 1 time in total.
User avatar
rockedge
Site Admin
Posts: 7021
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 3147 times
Been thanked: 2933 times
Contact:

Re: Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by rockedge ยป

Thanks @MochiMoppel, the script works great in KLV-Airedale! :thumbup2: :goodpost:

I downloaded the required font from here -> https://github.com/googlefonts/noto-emo ... rEmoji.ttf and placed in /usr/share/fonts/TFF.

Once in the font was in place it looks really good, and very useful!

Attachments
Screenshot.jpg
Screenshot.jpg (47.38 KiB) Viewed 1546 times
keniv
Posts: 694
Joined: Mon Jul 13, 2020 2:18 pm
Location: Scotland
Has thanked: 124 times
Been thanked: 72 times

Re: Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by keniv ยป

Copied the script to a blank file and named it "flags". Downloaded and installed NotoColorEmoji.ttf as outlined by @rockedge. Right clicked on the "flags" file and chose run in terminal and got a permission denied error. Did this in Bookworm 10.0.7. Any ideas as to what I did wrong?

Regards,

Ken.

User avatar
rockedge
Site Admin
Posts: 7021
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 3147 times
Been thanked: 2933 times
Contact:

Re: Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by rockedge ยป

you need to make the script executable!
You can use the file manager to do this or the terminal:

Code: Select all

chmod +x <my_script.sh>

or:

Code: Select all

chmod u+x <file>
User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by greengeek ยป

MochiMoppel wrote: Mon Aug 12, 2024 12:32 pm

emojione-android.ttf is a font installed in Fossapup64 9.5.

Where should one find this in F64-9.5? I looked in /usr/share/fonts but cannot see it.
Cheers!

EDIT: Ahhh - never mind - found it in the adrv.

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Show the flags ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฒ๐Ÿ‡น

Post by MochiMoppel ยป

greengeek wrote: Sun Oct 13, 2024 7:51 am

Where should one find this in F64-9.5? I looked in /usr/share/fonts but cannot see it.
Cheers!
EDIT: Ahhh - never mind - found it in the adrv.

Even if you don't have the font installed, you can still create the flag parade using Firefox, Librewolf or similar canines with following script:

Code: Select all

#! /bin/bash
TMPHTML=/tmp/flags.htm
echo '<meta charset=UTF-8><style>.flag{font-size:72px;line-height:0.8}</style>' > $TMPHTML
sed -r "/^#/d
s/(..)\t(.*)/\1\n<b>\1<\/b> \2<\/br>/" /usr/share/zoneinfo/iso3166.tab | sed "
/^..$/ y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/๐Ÿ‡ฆ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฎ๐Ÿ‡ฏ๐Ÿ‡ฐ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ถ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡บ๐Ÿ‡ป๐Ÿ‡ผ๐Ÿ‡ฝ๐Ÿ‡พ๐Ÿ‡ฟ/
/^..$/ s/.*/<span class=flag>&<\/span>/" >> $TMPHTML
defaultbrowser $TMPHTML

The script creates a barebone HTML page and calls defaultbrowser to display it.
As mentioned in the initial post it uses the browser's TwemojiMozilla.ttf font. Note that the flags are a bit different, they are not waving. Also noteworthy that this is one of the rare occasions where sed's y command comes handy. sed y/.../.../ works similar to the tr command and can replace a range of characters into different characters, but unlike tr it supports Unicode characters.

flags.png
flags.png (44.85 KiB) Viewed 1018 times
Post Reply

Return to โ€œProgrammingโ€