Skip to content

Instantly share code, notes, and snippets.

@Julien00859
Last active April 21, 2020 14:01
Show Gist options
  • Save Julien00859/7992bb19dd5b801d91f1e2baa1f4cc98 to your computer and use it in GitHub Desktop.
Save Julien00859/7992bb19dd5b801d91f1e2baa1f4cc98 to your computer and use it in GitHub Desktop.
Odoo fontawesome v4 to v5 automatic file transcripter

Fontawesome v4 to v5

Applicable to Odoo XML and JS files. See LICENSE file on for full copyright and licensing details.

The script was applied to the entire odoo codebase and was able to automatically convert most icons in a few seconds.

Warning

There are a few patterns the script doesn't detect or migrates wrong. They require your attention.

  • javascript tests click('.i.fa.fa-star-o')
  • code-controlled icons $('.fa-star').toggleClass('fa-star').toggleClass('fa-star-o')
  • css selectors .fa-star { color: gold }
  • html classes when a non fa class is put in between fa classes class="fa fa-fw mt4 fa-star-o" (wrongly translated as fas fa-fw mt4 fa-star-o)

You can find most of those icons by scanning the code for words containing a -o suffix, here is a regexp: \w-o\W.

Usage

usage: odoo-fontawesome.py [-h] file [file ...]

Translate font-awesome v4 icons to v5

positional arguments:
  file        file to translate

optional arguments:
  -h, --help  show this help message and exit
{"fa-500px": ["fa-500px", "fab"],
"fa-address-book-o": ["fa-address-book", "far"],
"fa-address-card-o": ["fa-address-card", "far"],
"fa-adn": ["fa-adn", "fab"],
"fa-amazon": ["fa-amazon", "fab"],
"fa-android": ["fa-android", "fab"],
"fa-angellist": ["fa-angellist", "fab"],
"fa-apple": ["fa-apple", "fab"],
"fa-area-chart": ["fa-chart-area", "fas"],
"fa-arrow-circle-o-down": ["fa-arrow-alt-circle-down", "far"],
"fa-arrow-circle-o-left": ["fa-arrow-alt-circle-left", "far"],
"fa-arrow-circle-o-right": ["fa-arrow-alt-circle-right", "far"],
"fa-arrow-circle-o-up": ["fa-arrow-alt-circle-up", "far"],
"fa-arrows": ["fa-arrows-alt", "fas"],
"fa-arrows-alt": ["fa-expand-arrows-alt", "fas"],
"fa-arrows-h": ["fa-arrows-alt-h", "fas"],
"fa-arrows-v": ["fa-arrows-alt-v", "fas"],
"fa-asl-interpreting": ["fa-american-sign-language-interpreting", "fas"],
"fa-automobile": ["fa-car", "fas"],
"fa-bandcamp": ["fa-bandcamp", "fab"],
"fa-bank": ["fa-university", "fas"],
"fa-bar-chart": ["fa-chart-bar", "far"],
"fa-bar-chart-o": ["fa-chart-bar", "far"],
"fa-bathtub": ["fa-bath", "fas"],
"fa-battery": ["fa-battery-full", "fas"],
"fa-battery-0": ["fa-battery-empty", "fas"],
"fa-battery-1": ["fa-battery-quarter", "fas"],
"fa-battery-2": ["fa-battery-half", "fas"],
"fa-battery-3": ["fa-battery-three-quarters", "fas"],
"fa-battery-4": ["fa-battery-full", "fas"],
"fa-behance": ["fa-behance", "fab"],
"fa-behance-square": ["fa-behance-square", "fab"],
"fa-bell-o": ["fa-bell", "far"],
"fa-bell-slash-o": ["fa-bell-slash", "far"],
"fa-bitbucket": ["fa-bitbucket", "fab"],
"fa-bitbucket-square": ["fa-bitbucket", "fab"],
"fa-bitcoin": ["fa-btc", "fab"],
"fa-black-tie": ["fa-black-tie", "fab"],
"fa-bluetooth": ["fa-bluetooth", "fab"],
"fa-bluetooth-b": ["fa-bluetooth-b", "fab"],
"fa-bookmark-o": ["fa-bookmark", "far"],
"fa-btc": ["fa-btc", "fab"],
"fa-building-o": ["fa-building", "far"],
"fa-buysellads": ["fa-buysellads", "fab"],
"fa-cab": ["fa-taxi", "fas"],
"fa-calendar": ["fa-calendar-alt", "fas"],
"fa-calendar-check-o": ["fa-calendar-check", "far"],
"fa-calendar-minus-o": ["fa-calendar-minus", "far"],
"fa-calendar-o": ["fa-calendar", "far"],
"fa-calendar-plus-o": ["fa-calendar-plus", "far"],
"fa-calendar-times-o": ["fa-calendar-times", "far"],
"fa-caret-square-o-down": ["fa-caret-square-down", "far"],
"fa-caret-square-o-left": ["fa-caret-square-left", "far"],
"fa-caret-square-o-right": ["fa-caret-square-right", "far"],
"fa-caret-square-o-up": ["fa-caret-square-up", "far"],
"fa-cc": ["fa-closed-captioning", "far"],
"fa-cc-amex": ["fa-cc-amex", "fab"],
"fa-cc-diners-club": ["fa-cc-diners-club", "fab"],
"fa-cc-discover": ["fa-cc-discover", "fab"],
"fa-cc-jcb": ["fa-cc-jcb", "fab"],
"fa-cc-mastercard": ["fa-cc-mastercard", "fab"],
"fa-cc-paypal": ["fa-cc-paypal", "fab"],
"fa-cc-stripe": ["fa-cc-stripe", "fab"],
"fa-cc-visa": ["fa-cc-visa", "fab"],
"fa-chain": ["fa-link", "fas"],
"fa-chain-broken": ["fa-unlink", "fas"],
"fa-check-circle-o": ["fa-check-circle", "far"],
"fa-check-square-o": ["fa-check-square", "far"],
"fa-chrome": ["fa-chrome", "fab"],
"fa-circle-o": ["fa-circle", "far"],
"fa-circle-o-notch": ["fa-circle-notch", "fas"],
"fa-circle-thin": ["fa-circle", "far"],
"fa-clipboard": ["fa-clipboard", "far"],
"fa-clock-o": ["fa-clock", "far"],
"fa-clone": ["fa-clone", "far"],
"fa-close": ["fa-times", "fas"],
"fa-cloud-download": ["fa-cloud-download-alt", "fas"],
"fa-cloud-upload": ["fa-cloud-upload-alt", "fas"],
"fa-cny": ["fa-yen-sign", "fas"],
"fa-code-fork": ["fa-code-branch", "fas"],
"fa-codepen": ["fa-codepen", "fab"],
"fa-codiepie": ["fa-codiepie", "fab"],
"fa-comment-o": ["fa-comment", "far"],
"fa-commenting": ["fa-comment-dots", "fas"],
"fa-commenting-o": ["fa-comment-dots", "far"],
"fa-comments-o": ["fa-comments", "far"],
"fa-compass": ["fa-compass", "far"],
"fa-connectdevelop": ["fa-connectdevelop", "fab"],
"fa-contao": ["fa-contao", "fab"],
"fa-copyright": ["fa-copyright", "far"],
"fa-creative-commons": ["fa-creative-commons", "fab"],
"fa-credit-card": ["fa-credit-card", "far"],
"fa-credit-card-alt": ["fa-credit-card", "fas"],
"fa-css3": ["fa-css3", "fab"],
"fa-cutlery": ["fa-utensils", "fas"],
"fa-dashboard": ["fa-tachometer-alt", "fas"],
"fa-dashcube": ["fa-dashcube", "fab"],
"fa-deafness": ["fa-deaf", "fas"],
"fa-dedent": ["fa-outdent", "fas"],
"fa-delicious": ["fa-delicious", "fab"],
"fa-deviantart": ["fa-deviantart", "fab"],
"fa-diamond": ["fa-gem", "far"],
"fa-digg": ["fa-digg", "fab"],
"fa-dollar": ["fa-dollar-sign", "fas"],
"fa-dot-circle-o": ["fa-dot-circle", "far"],
"fa-dribbble": ["fa-dribbble", "fab"],
"fa-drivers-license": ["fa-id-card", "fas"],
"fa-drivers-license-o": ["fa-id-card", "far"],
"fa-dropbox": ["fa-dropbox", "fab"],
"fa-drupal": ["fa-drupal", "fab"],
"fa-edge": ["fa-edge", "fab"],
"fa-eercast": ["fa-sellcast", "fab"],
"fa-empire": ["fa-empire", "fab"],
"fa-envelope-o": ["fa-envelope", "far"],
"fa-envelope-open-o": ["fa-envelope-open", "far"],
"fa-envira": ["fa-envira", "fab"],
"fa-etsy": ["fa-etsy", "fab"],
"fa-eur": ["fa-euro-sign", "fas"],
"fa-euro": ["fa-euro-sign", "fas"],
"fa-exchange": ["fa-exchange-alt", "fas"],
"fa-expeditedssl": ["fa-expeditedssl", "fab"],
"fa-external-link": ["fa-external-link-alt", "fas"],
"fa-external-link-square": ["fa-external-link-square-alt", "fas"],
"fa-eye": ["fa-eye", "far"],
"fa-eye-slash": ["fa-eye-slash", "far"],
"fa-eyedropper": ["fa-eye-dropper", "fas"],
"fa-facebook": ["fa-facebook-f", "fab"],
"fa-facebook-f": ["fa-facebook-f", "fab"],
"fa-facebook-official": ["fa-facebook", "fab"],
"fa-facebook-square": ["fa-facebook-square", "fab"],
"fa-feed": ["fa-rss", "fas"],
"fa-file-archive-o": ["fa-file-archive", "far"],
"fa-file-audio-o": ["fa-file-audio", "far"],
"fa-file-code-o": ["fa-file-code", "far"],
"fa-file-excel-o": ["fa-file-excel", "far"],
"fa-file-image-o": ["fa-file-image", "far"],
"fa-file-movie-o": ["fa-file-video", "far"],
"fa-file-o": ["fa-file", "far"],
"fa-file-pdf-o": ["fa-file-pdf", "far"],
"fa-file-photo-o": ["fa-file-image", "far"],
"fa-file-picture-o": ["fa-file-image", "far"],
"fa-file-powerpoint-o": ["fa-file-powerpoint", "far"],
"fa-file-sound-o": ["fa-file-audio", "far"],
"fa-file-text": ["fa-file-alt", "fas"],
"fa-file-text-o": ["fa-file-alt", "far"],
"fa-file-video-o": ["fa-file-video", "far"],
"fa-file-word-o": ["fa-file-word", "far"],
"fa-file-zip-o": ["fa-file-archive", "far"],
"fa-files-o": ["fa-copy", "far"],
"fa-firefox": ["fa-firefox", "fab"],
"fa-first-order": ["fa-first-order", "fab"],
"fa-flag-o": ["fa-flag", "far"],
"fa-flash": ["fa-bolt", "fas"],
"fa-flickr": ["fa-flickr", "fab"],
"fa-floppy-o": ["fa-save", "far"],
"fa-folder-o": ["fa-folder", "far"],
"fa-folder-open-o": ["fa-folder-open", "far"],
"fa-font-awesome": ["fa-font-awesome", "fab"],
"fa-fonticons": ["fa-fonticons", "fab"],
"fa-fort-awesome": ["fa-fort-awesome", "fab"],
"fa-forumbee": ["fa-forumbee", "fab"],
"fa-foursquare": ["fa-foursquare", "fab"],
"fa-free-code-camp": ["fa-free-code-camp", "fab"],
"fa-frown-o": ["fa-frown", "far"],
"fa-futbol-o": ["fa-futbol", "far"],
"fa-gbp": ["fa-pound-sign", "fas"],
"fa-ge": ["fa-empire", "fab"],
"fa-gear": ["fa-cog", "fas"],
"fa-gears": ["fa-cogs", "fas"],
"fa-get-pocket": ["fa-get-pocket", "fab"],
"fa-gg": ["fa-gg", "fab"],
"fa-gg-circle": ["fa-gg-circle", "fab"],
"fa-git": ["fa-git", "fab"],
"fa-git-square": ["fa-git-square", "fab"],
"fa-github": ["fa-github", "fab"],
"fa-github-alt": ["fa-github-alt", "fab"],
"fa-github-square": ["fa-github-square", "fab"],
"fa-gitlab": ["fa-gitlab", "fab"],
"fa-gittip": ["fa-gratipay", "fab"],
"fa-glass": ["fa-glass-martini", "fas"],
"fa-glide": ["fa-glide", "fab"],
"fa-glide-g": ["fa-glide-g", "fab"],
"fa-google": ["fa-google", "fab"],
"fa-google-plus": ["fa-google-plus-g", "fab"],
"fa-google-plus-circle": ["fa-google-plus", "fab"],
"fa-google-plus-official": ["fa-google-plus", "fab"],
"fa-google-plus-square": ["fa-google-plus-square", "fab"],
"fa-google-wallet": ["fa-google-wallet", "fab"],
"fa-gratipay": ["fa-gratipay", "fab"],
"fa-grav": ["fa-grav", "fab"],
"fa-group": ["fa-users", "fas"],
"fa-hacker-news": ["fa-hacker-news", "fab"],
"fa-hand-grab-o": ["fa-hand-rock", "far"],
"fa-hand-lizard-o": ["fa-hand-lizard", "far"],
"fa-hand-o-down": ["fa-hand-point-down", "far"],
"fa-hand-o-left": ["fa-hand-point-left", "far"],
"fa-hand-o-right": ["fa-hand-point-right", "far"],
"fa-hand-o-up": ["fa-hand-point-up", "far"],
"fa-hand-paper-o": ["fa-hand-paper", "far"],
"fa-hand-peace-o": ["fa-hand-peace", "far"],
"fa-hand-pointer-o": ["fa-hand-pointer", "far"],
"fa-hand-rock-o": ["fa-hand-rock", "far"],
"fa-hand-scissors-o": ["fa-hand-scissors", "far"],
"fa-hand-spock-o": ["fa-hand-spock", "far"],
"fa-hand-stop-o": ["fa-hand-paper", "far"],
"fa-handshake-o": ["fa-handshake", "far"],
"fa-hard-of-hearing": ["fa-deaf", "fas"],
"fa-hdd-o": ["fa-hdd", "far"],
"fa-header": ["fa-heading", "fas"],
"fa-heart-o": ["fa-heart", "far"],
"fa-hospital-o": ["fa-hospital", "far"],
"fa-hotel": ["fa-bed", "fas"],
"fa-hourglass-1": ["fa-hourglass-start", "fas"],
"fa-hourglass-2": ["fa-hourglass-half", "fas"],
"fa-hourglass-3": ["fa-hourglass-end", "fas"],
"fa-hourglass-o": ["fa-hourglass", "far"],
"fa-houzz": ["fa-houzz", "fab"],
"fa-html5": ["fa-html5", "fab"],
"fa-id-badge": ["fa-id-badge", "far"],
"fa-id-card-o": ["fa-id-card", "far"],
"fa-ils": ["fa-shekel-sign", "fas"],
"fa-image": ["fa-image", "far"],
"fa-imdb": ["fa-imdb", "fab"],
"fa-inr": ["fa-rupee-sign", "fas"],
"fa-instagram": ["fa-instagram", "fab"],
"fa-institution": ["fa-university", "fas"],
"fa-internet-explorer": ["fa-internet-explorer", "fab"],
"fa-intersex": ["fa-transgender", "fas"],
"fa-ioxhost": ["fa-ioxhost", "fab"],
"fa-joomla": ["fa-joomla", "fab"],
"fa-jpy": ["fa-yen-sign", "fas"],
"fa-jsfiddle": ["fa-jsfiddle", "fab"],
"fa-keyboard-o": ["fa-keyboard", "far"],
"fa-krw": ["fa-won-sign", "fas"],
"fa-lastfm": ["fa-lastfm", "fab"],
"fa-lastfm-square": ["fa-lastfm-square", "fab"],
"fa-leanpub": ["fa-leanpub", "fab"],
"fa-legal": ["fa-gavel", "fas"],
"fa-lemon-o": ["fa-lemon", "far"],
"fa-level-down": ["fa-level-down-alt", "fas"],
"fa-level-up": ["fa-level-up-alt", "fas"],
"fa-life-bouy": ["fa-life-ring", "far"],
"fa-life-buoy": ["fa-life-ring", "far"],
"fa-life-ring": ["fa-life-ring", "far"],
"fa-life-saver": ["fa-life-ring", "far"],
"fa-lightbulb-o": ["fa-lightbulb", "far"],
"fa-line-chart": ["fa-chart-line", "fas"],
"fa-linkedin": ["fa-linkedin-in", "fab"],
"fa-linkedin-square": ["fa-linkedin", "fab"],
"fa-linode": ["fa-linode", "fab"],
"fa-linux": ["fa-linux", "fab"],
"fa-list-alt": ["fa-list-alt", "far"],
"fa-long-arrow-down": ["fa-long-arrow-alt-down", "fas"],
"fa-long-arrow-left": ["fa-long-arrow-alt-left", "fas"],
"fa-long-arrow-right": ["fa-long-arrow-alt-right", "fas"],
"fa-long-arrow-up": ["fa-long-arrow-alt-up", "fas"],
"fa-mail-forward": ["fa-share", "fas"],
"fa-mail-reply": ["fa-reply", "fas"],
"fa-mail-reply-all": ["fa-reply-all", "fas"],
"fa-map-marker": ["fa-map-marker-alt", "fas"],
"fa-map-o": ["fa-map", "far"],
"fa-maxcdn": ["fa-maxcdn", "fab"],
"fa-meanpath": ["fa-font-awesome", "fab"],
"fa-medium": ["fa-medium", "fab"],
"fa-meetup": ["fa-meetup", "fab"],
"fa-meh-o": ["fa-meh", "far"],
"fa-minus-square-o": ["fa-minus-square", "far"],
"fa-mixcloud": ["fa-mixcloud", "fab"],
"fa-mobile": ["fa-mobile-alt", "fas"],
"fa-mobile-phone": ["fa-mobile-alt", "fas"],
"fa-modx": ["fa-modx", "fab"],
"fa-money": ["fa-money-bill-alt", "far"],
"fa-moon-o": ["fa-moon", "far"],
"fa-mortar-board": ["fa-graduation-cap", "fas"],
"fa-navicon": ["fa-bars", "fas"],
"fa-newspaper-o": ["fa-newspaper", "far"],
"fa-object-group": ["fa-object-group", "far"],
"fa-object-ungroup": ["fa-object-ungroup", "far"],
"fa-odnoklassniki": ["fa-odnoklassniki", "fab"],
"fa-odnoklassniki-square": ["fa-odnoklassniki-square", "fab"],
"fa-opencart": ["fa-opencart", "fab"],
"fa-openid": ["fa-openid", "fab"],
"fa-opera": ["fa-opera", "fab"],
"fa-optin-monster": ["fa-optin-monster", "fab"],
"fa-pagelines": ["fa-pagelines", "fab"],
"fa-paper-plane-o": ["fa-paper-plane", "far"],
"fa-paste": ["fa-clipboard", "far"],
"fa-pause-circle-o": ["fa-pause-circle", "far"],
"fa-paypal": ["fa-paypal", "fab"],
"fa-pencil": ["fa-pencil-alt", "fas"],
"fa-pencil-square": ["fa-pen-square", "fas"],
"fa-pencil-square-o": ["fa-edit", "far"],
"fa-photo": ["fa-image", "far"],
"fa-picture-o": ["fa-image", "far"],
"fa-pie-chart": ["fa-chart-pie", "fas"],
"fa-pied-piper": ["fa-pied-piper", "fab"],
"fa-pied-piper-alt": ["fa-pied-piper-alt", "fab"],
"fa-pied-piper-pp": ["fa-pied-piper-pp", "fab"],
"fa-pinterest": ["fa-pinterest", "fab"],
"fa-pinterest-p": ["fa-pinterest-p", "fab"],
"fa-pinterest-square": ["fa-pinterest-square", "fab"],
"fa-play-circle-o": ["fa-play-circle", "far"],
"fa-plus-square-o": ["fa-plus-square", "far"],
"fa-product-hunt": ["fa-product-hunt", "fab"],
"fa-qq": ["fa-qq", "fab"],
"fa-question-circle-o": ["fa-question-circle", "far"],
"fa-quora": ["fa-quora", "fab"],
"fa-ra": ["fa-rebel", "fab"],
"fa-ravelry": ["fa-ravelry", "fab"],
"fa-rebel": ["fa-rebel", "fab"],
"fa-reddit": ["fa-reddit", "fab"],
"fa-reddit-alien": ["fa-reddit-alien", "fab"],
"fa-reddit-square": ["fa-reddit-square", "fab"],
"fa-refresh": ["fa-sync", "fas"],
"fa-registered": ["fa-registered", "far"],
"fa-remove": ["fa-times", "fas"],
"fa-renren": ["fa-renren", "fab"],
"fa-reorder": ["fa-bars", "fas"],
"fa-repeat": ["fa-redo", "fas"],
"fa-resistance": ["fa-rebel", "fab"],
"fa-rmb": ["fa-yen-sign", "fas"],
"fa-rotate-left": ["fa-undo", "fas"],
"fa-rotate-right": ["fa-redo", "fas"],
"fa-rouble": ["fa-ruble-sign", "fas"],
"fa-rub": ["fa-ruble-sign", "fas"],
"fa-ruble": ["fa-ruble-sign", "fas"],
"fa-rupee": ["fa-rupee-sign", "fas"],
"fa-s15": ["fa-bath", "fas"],
"fa-safari": ["fa-safari", "fab"],
"fa-scissors": ["fa-cut", "fas"],
"fa-scribd": ["fa-scribd", "fab"],
"fa-sellsy": ["fa-sellsy", "fab"],
"fa-send": ["fa-paper-plane", "fas"],
"fa-send-o": ["fa-paper-plane", "far"],
"fa-share-square-o": ["fa-share-square", "far"],
"fa-shekel": ["fa-shekel-sign", "fas"],
"fa-sheqel": ["fa-shekel-sign", "fas"],
"fa-shield": ["fa-shield-alt", "fas"],
"fa-shirtsinbulk": ["fa-shirtsinbulk", "fab"],
"fa-sign-in": ["fa-sign-in-alt", "fas"],
"fa-sign-out": ["fa-sign-out-alt", "fas"],
"fa-signing": ["fa-sign-language", "fas"],
"fa-simplybuilt": ["fa-simplybuilt", "fab"],
"fa-skyatlas": ["fa-skyatlas", "fab"],
"fa-skype": ["fa-skype", "fab"],
"fa-slack": ["fa-slack", "fab"],
"fa-sliders": ["fa-sliders-h", "fas"],
"fa-slideshare": ["fa-slideshare", "fab"],
"fa-smile-o": ["fa-smile", "far"],
"fa-snapchat": ["fa-snapchat", "fab"],
"fa-snapchat-ghost": ["fa-snapchat-ghost", "fab"],
"fa-snapchat-square": ["fa-snapchat-square", "fab"],
"fa-snowflake-o": ["fa-snowflake", "far"],
"fa-soccer-ball-o": ["fa-futbol", "far"],
"fa-sort-alpha-asc": ["fa-sort-alpha-down", "fas"],
"fa-sort-alpha-desc": ["fa-sort-alpha-up", "fas"],
"fa-sort-amount-asc": ["fa-sort-amount-down", "fas"],
"fa-sort-amount-desc": ["fa-sort-amount-up", "fas"],
"fa-sort-asc": ["fa-sort-up", "fas"],
"fa-sort-desc": ["fa-sort-down", "fas"],
"fa-sort-numeric-asc": ["fa-sort-numeric-down", "fas"],
"fa-sort-numeric-desc": ["fa-sort-numeric-up", "fas"],
"fa-soundcloud": ["fa-soundcloud", "fab"],
"fa-spoon": ["fa-utensil-spoon", "fas"],
"fa-spotify": ["fa-spotify", "fab"],
"fa-square-o": ["fa-square", "far"],
"fa-stack-exchange": ["fa-stack-exchange", "fab"],
"fa-stack-overflow": ["fa-stack-overflow", "fab"],
"fa-star-half-empty": ["fa-star-half", "far"],
"fa-star-half-full": ["fa-star-half", "far"],
"fa-star-half-o": ["fa-star-half", "far"],
"fa-star-o": ["fa-star", "far"],
"fa-steam": ["fa-steam", "fab"],
"fa-steam-square": ["fa-steam-square", "fab"],
"fa-sticky-note-o": ["fa-sticky-note", "far"],
"fa-stop-circle-o": ["fa-stop-circle", "far"],
"fa-stumbleupon": ["fa-stumbleupon", "fab"],
"fa-stumbleupon-circle": ["fa-stumbleupon-circle", "fab"],
"fa-sun-o": ["fa-sun", "far"],
"fa-superpowers": ["fa-superpowers", "fab"],
"fa-support": ["fa-life-ring", "far"],
"fa-tablet": ["fa-tablet-alt", "fas"],
"fa-tachometer": ["fa-tachometer-alt", "fas"],
"fa-telegram": ["fa-telegram", "fab"],
"fa-television": ["fa-tv", "fas"],
"fa-tencent-weibo": ["fa-tencent-weibo", "fab"],
"fa-themeisle": ["fa-themeisle", "fab"],
"fa-thermometer": ["fa-thermometer-full", "fas"],
"fa-thermometer-0": ["fa-thermometer-empty", "fas"],
"fa-thermometer-1": ["fa-thermometer-quarter", "fas"],
"fa-thermometer-2": ["fa-thermometer-half", "fas"],
"fa-thermometer-3": ["fa-thermometer-three-quarters", "fas"],
"fa-thermometer-4": ["fa-thermometer-full", "fas"],
"fa-thumb-tack": ["fa-thumbtack", "fas"],
"fa-thumbs-o-down": ["fa-thumbs-down", "far"],
"fa-thumbs-o-up": ["fa-thumbs-up", "far"],
"fa-ticket": ["fa-ticket-alt", "fas"],
"fa-times-circle-o": ["fa-times-circle", "far"],
"fa-times-rectangle": ["fa-window-close", "fas"],
"fa-times-rectangle-o": ["fa-window-close", "far"],
"fa-toggle-down": ["fa-caret-square-down", "far"],
"fa-toggle-left": ["fa-caret-square-left", "far"],
"fa-toggle-right": ["fa-caret-square-right", "far"],
"fa-toggle-up": ["fa-caret-square-up", "far"],
"fa-trash": ["fa-trash-alt", "fas"],
"fa-trash-o": ["fa-trash-alt", "far"],
"fa-trello": ["fa-trello", "fab"],
"fa-tripadvisor": ["fa-tripadvisor", "fab"],
"fa-try": ["fa-lira-sign", "fas"],
"fa-tumblr": ["fa-tumblr", "fab"],
"fa-tumblr-square": ["fa-tumblr-square", "fab"],
"fa-turkish-lira": ["fa-lira-sign", "fas"],
"fa-twitch": ["fa-twitch", "fab"],
"fa-twitter": ["fa-twitter", "fab"],
"fa-twitter-square": ["fa-twitter-square", "fab"],
"fa-unsorted": ["fa-sort", "fas"],
"fa-usb": ["fa-usb", "fab"],
"fa-usd": ["fa-dollar-sign", "fas"],
"fa-user-circle-o": ["fa-user-circle", "far"],
"fa-user-o": ["fa-user", "far"],
"fa-vcard": ["fa-address-card", "fas"],
"fa-vcard-o": ["fa-address-card", "far"],
"fa-viacoin": ["fa-viacoin", "fab"],
"fa-viadeo": ["fa-viadeo", "fab"],
"fa-viadeo-square": ["fa-viadeo-square", "fab"],
"fa-video-camera": ["fa-video", "fas"],
"fa-vimeo": ["fa-vimeo-v", "fab"],
"fa-vimeo-square": ["fa-vimeo-square", "fab"],
"fa-vine": ["fa-vine", "fab"],
"fa-vk": ["fa-vk", "fab"],
"fa-volume-control-phone": ["fa-phone-volume", "fas"],
"fa-warning": ["fa-exclamation-triangle", "fas"],
"fa-wechat": ["fa-weixin", "fab"],
"fa-weibo": ["fa-weibo", "fab"],
"fa-weixin": ["fa-weixin", "fab"],
"fa-whatsapp": ["fa-whatsapp", "fab"],
"fa-wheelchair-alt": ["fa-accessible-icon", "fab"],
"fa-wikipedia-w": ["fa-wikipedia-w", "fab"],
"fa-window-close-o": ["fa-window-close", "far"],
"fa-window-maximize": ["fa-window-maximize", "far"],
"fa-window-restore": ["fa-window-restore", "far"],
"fa-windows": ["fa-windows", "fab"],
"fa-won": ["fa-won-sign", "fas"],
"fa-wordpress": ["fa-wordpress", "fab"],
"fa-wpbeginner": ["fa-wpbeginner", "fab"],
"fa-wpexplorer": ["fa-wpexplorer", "fab"],
"fa-wpforms": ["fa-wpforms", "fab"],
"fa-xing": ["fa-xing", "fab"],
"fa-xing-square": ["fa-xing-square", "fab"],
"fa-y-combinator": ["fa-y-combinator", "fab"],
"fa-y-combinator-square": ["fa-hacker-news", "fab"],
"fa-yahoo": ["fa-yahoo", "fab"],
"fa-yc": ["fa-y-combinator", "fab"],
"fa-yc-square": ["fa-hacker-news", "fab"],
"fa-yelp": ["fa-yelp", "fab"],
"fa-yen": ["fa-yen-sign", "fas"],
"fa-yoast": ["fa-yoast", "fab"],
"fa-youtube": ["fa-youtube", "fab"],
"fa-youtube-play": ["fa-youtube", "fab"],
"fa-youtube-square": ["fa-youtube-square", "fab"]}
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import pathlib
import re
import sys
with pathlib.Path(__file__).resolve().parent.joinpath('fontmap.json').open() as fd:
fontmap = json.load(fd)
"""
Because it's quite a mess, here are some insights :
1) v4 font-awesome had a single "fa" prefix and one font name per icon
2) v5 font-awesome has multiple prefixes ('fas', 'far', 'fab') that
serve as icon style, several icons share the same name. An icon is
identified by the pair (icon style, icon name).
4) Most v4 icons suffixed with "-o" now have the far style without this
suffix. We translate them (along with all other "special" fonts)
using the fontmap json file.
3) Most v4 icons have the fas style in v5 with the same name, they are
not covered in the fontmap.json file and are translated by the
'*_generic_re' regexps bellow.
5) Beside icon style and name, each icon can be modded to be larger,
smaller or animated. Those mods don't change between v4 and v5.
"""
# style="fa fa-fw fa-lg fa-circle-o"
# ^^^^^^^^^^^^ ^
# g1:mod ^^^^^^^^^^^
# g2:v4 g3:suffix so the regexp match circle-o and not circle
class_re = re.compile(r"fa\s+((?:(?:{mods})\s+)*)({v4})([^\-a-z])".format(
mods=r"|".join([r"fa-xs", r"fa-sm", r"fa-lg", r"fa-\d\d?x", r"fa-fw",
r"fa-ul", r"fa-li", r"fa-border", r"fa-pull-(?:left|right)",
r"fa-spin", r"fa-pulse", r"fa-rotate-\d+",
r"fa-flip-(?:horizontal|vertical)", r"fa-stack(?:-[12]x)?",
r"fa-inverse"]),
v4=r"|".join(fontmap.keys())
))
def _class_re_repl(match):
v5, style = fontmap[match.group(2)]
return f"{style} {match.group(1)}{v5}{match.group(3)}"
# style="fa fa-circle"
# ^
# g1:prefix so the regexp doesn't match 'foofa fa-circle'
#
class_generic_re = re.compile(r"(\W)fa fa-")
def _class_generic_re_repl(match):
return "%sfas fa-" % match.group(1)
# icon="fa-circle-o"
# icon:'fa-circle-o'
# ^ ^^^^^^^^^^^
# ^ g3:v4 ^
# g2:quote g4:quote to reuse the same ones
# g1 match either js : either xml =
icon_re = re.compile(r"""icon(\s*[=:]\s*)(["'])({v4})(["'])""".format(
v4=r"|".join(fontmap.keys())))
def _icon_re_repl(match):
v5, style = fontmap[match.group(3)]
return f"icon{match.group(1)}{match.group(2)}{style} {v5}{match.group(4)}"
# icon="fa-circle"
# icon:"fa-circle"
# ^ ^^^^^^^^^
# ^ g3:v4 ^
# g2:quote g4:quote to reuse the same ones
# g1 match either js : either xml =
icon_generic_re = re.compile(r"""icon(\s*[=:]\s*)(["'])(fa-[\w-]+)(["'])""")
def _icon_generic_re_repl(match):
return f"icon{match.group(1)}{match.group(2)}fas {match.group(3)}{match.group(4)}"
# <field name="icon">fa-circle-o</field>
# ^ ^ ^^^^^^^^^^^
# g3:v4
# g1 g2: quotes to reuse the same ones
field_re = re.compile(r"""<field name=(["'])icon(["'])>({v4})</field>""".format(
v4=r"|fa-".join(fontmap.keys())))
def _field_re_repl(match):
v5, style = fontmap[match.group(3)]
return f"<field name={match.group(1)}icon{match.group(2)}>{style} {v5}</field>"
# <field name="icon">fa-circle</field>
# ^ ^ ^^^^^^^^^
# g3:v4
# g1 g2: quotes to reuse the same ones
field_generic_re = re.compile(r"""<field name=(["'])icon(["i])>(fa-[\\w-]+)</field>""")
def _field_generic_re_repl(match):
return f"<field name={match.group(1)}icon{match.group(2)}>fas {match.group(3)}</field>"
def translate(arch):
"""
Apply several regexp substitution on a xml architecture to migrate
v4 font-awesome fonts to v5. Returns the translated architecture
with the total translation count.
"""
arch, cnt1 = class_re.subn(_class_re_repl, arch)
arch, cnt2 = class_generic_re.subn(_class_generic_re_repl, arch)
arch, cnt3 = icon_re.subn(_icon_re_repl, arch)
arch, cnt4 = icon_generic_re.subn(_icon_generic_re_repl, arch)
arch, cnt5 = field_re.subn(_field_re_repl, arch)
arch, cnt6 = field_generic_re.subn(_field_generic_re_repl, arch)
return arch, cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6
def main():
from argparse import ArgumentParser
parser = ArgumentParser(description="Translate font-awesome v4 icons to v5")
parser.add_argument('file', nargs='+', help="file to translate")
options = parser.parse_args()
for file in options.file:
with open(file) as fd:
content = fd.read()
content, count = translate(content)
if count:
with open(file, 'w') as fd:
fd.write(content)
print(f"Found and replaced {count} icons in {file}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment