定制 outhebox/blade-flags 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

outhebox/blade-flags

Composer 安装命令:

composer require outhebox/blade-flags

包简介

A package to easily make use of country & language flags in your Laravel Blade views.

README 文档

README

Blade Flags — SVG country and language flags for Laravel, Vue, React, and JavaScript

Laravel | Vue | React | Vanilla JS | Variants | Contributing

Latest Stable Version npm version Total Downloads PHP from Packagist Laravel Version

Introduction

1,759 SVG country and language flags for Laravel Blade, Vue, React, and vanilla JavaScript. Three flag styles, 128 language mappings, and full support for regional variants like ar-sa, en-us, and fr-ca. Works great with Inertia.js.

Use them anywhere — locale switchers, address forms, dashboards, or admin panels.

Variant Blade JS import Countries Languages Source
Default (rounded) <x-flag-country-us /> defaultFlags 264 281 TwEmoji
Circle <x-flag-circle-country-us /> circleFlags 405 275 circle-flags
Flat (4:3) <x-flag-flat-country-us /> flatFlags 270 264 flag-icons

For a full list of available icons see the SVG directories: default, circle, flat.

Installation

# Laravel / PHP
composer require outhebox/blade-flags

# Vue
npm install @blade-flags/core @blade-flags/vue

# React
npm install @blade-flags/core @blade-flags/react

# Vanilla JS / Node
npm install @blade-flags/core

Laravel / Blade

Requires PHP 8.0+ and Laravel 9+. Uses Blade Icons under the hood — see their readme for caching and additional features.

Watch a 3-minute video by Povilas Korop showcasing the package.

Icons can be used as self-closing Blade components which will be compiled to SVG icons.

Default (Rounded Rectangle)

<x-flag-country-us />
<x-flag-country-gb />
<x-flag-country-br />
<x-flag-country-cn />
<x-flag-country-ru />

...produces this:

US flag (default variant) GB flag (default variant) BR flag (default variant) CN flag (default variant) RU flag (default variant)

<x-flag-language-en />
<x-flag-language-ar />
<x-flag-language-es />

...produces this:

English language flag Arabic language flag Spanish language flag

Circle

<x-flag-circle-country-us />
<x-flag-circle-country-gb />
<x-flag-circle-country-br />
<x-flag-circle-country-cn />
<x-flag-circle-country-ru />

...produces this:

US flag (circle variant) GB flag (circle variant) BR flag (circle variant) CN flag (circle variant) RU flag (circle variant)

<x-flag-circle-language-en />
<x-flag-circle-language-ar />
<x-flag-circle-language-ar-sa />
<x-flag-circle-language-ar-eg />

...produces this:

English language flag (circle) Arabic language flag (circle) Arabic (Saudi Arabia) language flag (circle) Arabic (Egypt) language flag (circle)

Flat (4:3 Rectangle)

<x-flag-flat-country-us />
<x-flag-flat-country-gb />
<x-flag-flat-country-br />
<x-flag-flat-country-cn />
<x-flag-flat-country-ru />

...produces this:

US flag (flat variant) GB flag (flat variant) BR flag (flat variant) CN flag (flat variant) RU flag (flat variant)

<x-flag-flat-language-en />
<x-flag-flat-language-ar />
<x-flag-flat-language-fr />

...produces this:

English language flag (flat) Arabic language flag (flat) French language flag (flat)

Classes & Attributes

You can pass classes to any variant:

<x-flag-country-us class="w-6 h-6"/>
<x-flag-circle-country-us class="w-6 h-6"/>
<x-flag-flat-country-us class="w-6 h-6"/>

Dynamic Icons

For dynamic icon names (e.g. from a database or variable), use the @svg Blade directive:

@svg('flag-country-'.$country->iso2_code)
@svg('flag-circle-country-'.$country->iso2_code, 'w-6 h-6')
@svg('flag-flat-country-'.$country->iso2_code)

@svg('flag-language-'.$language->code)
@svg('flag-circle-language-'.$language->code, 'w-6 h-6')
@svg('flag-flat-language-'.$language->code)

Or the svg() helper in PHP:

svg('flag-country-us')->toHtml()
svg('flag-circle-country-us', 'w-6 h-6')->toHtml()

Raw SVG Icons

Publish the raw SVG files as public assets:

php artisan vendor:publish --tag=blade-flags --force
php artisan vendor:publish --tag=blade-flags-circle --force
php artisan vendor:publish --tag=blade-flags-flat --force

Then use them in your views:

<img src="{{ asset('vendor/blade-flags/country-us.svg') }}" width="32" height="32"/>
<img src="{{ asset('vendor/blade-flags-circle/circle-country-us.svg') }}" width="32" height="32"/>
<img src="{{ asset('vendor/blade-flags-flat/flat-country-us.svg') }}" width="32" height="32"/>

Configuration

Blade Flags also offers the ability to use features from Blade Icons like default classes, default attributes, etc. If you'd like to configure these, publish the blade-flags.php config file:

php artisan vendor:publish --tag=blade-flags-config

Language Flag Overrides

By default, language flags use the country mappings defined in config/language-countries.json (e.g. ar → UAE, en → UK). You can override these defaults per-language:

  1. Publish the config file:

    php artisan vendor:publish --tag=blade-flags-config
  2. Edit config/blade-flags.php to set your preferred mappings:

    'language_overrides' => [
        'ar' => ['default' => 'sa'],  // Arabic → Saudi Arabia
        'en' => ['default' => 'us'],  // English → United States
    ],
  3. Publish the SVG assets and apply your overrides:

    php artisan vendor:publish --tag=blade-flags --force
    php artisan vendor:publish --tag=blade-flags-circle --force
    php artisan vendor:publish --tag=blade-flags-flat --force
    php artisan blade-flags:generate

The blade-flags:generate command reads the package defaults, merges your overrides, and regenerates the language flag SVGs in the published vendor directories.

Vue

Works with Vue 3.3+. Ideal for Inertia.js apps.

<script setup>
import { Flag } from '@blade-flags/vue'
import { circleFlags } from '@blade-flags/core/flags/circle'
</script>

<template>
  <!-- Dynamic: pass the full map, resolve by code at runtime -->
  <Flag :code="user.country" :flags="circleFlags" />
  <Flag code="ar-sa" type="language" :flags="circleFlags" />
</template>

React

Works with React 18+.

import { Flag } from '@blade-flags/react'
import { circleFlags } from '@blade-flags/core/flags/circle'

// Dynamic: pass the full map, resolve by code at runtime
<Flag code={user.country} flags={circleFlags} />
<Flag code="ar-sa" type="language" flags={circleFlags} />

Vanilla JS

Use @blade-flags/core directly in any JavaScript or TypeScript project:

import { resolveFlag } from '@blade-flags/core'
import { circleFlags } from '@blade-flags/core/flags/circle'

// Dynamic: resolve by code at runtime (loads all flags in the variant)
const svg = resolveFlag(circleFlags, user.country)
document.getElementById('flag').innerHTML = svg

Tree-Shaking & Bundle Size

Every flag is a named export. If you know which flags you need at build time, import them directly — your bundler will tree-shake the rest:

// Only the flags you import end up in your bundle
import { countryUs, countryGb, languageAr, languageArSa } from '@blade-flags/core/flags/circle'

Flag names follow the pattern country{Code} and language{Code} in camelCase:

SVG key Named export Type
country-us countryUs Country
country-gb-eng countryGbEng Country (region)
language-ar languageAr Language
language-ar-sa languageArSa Language (regional)

For dynamic use (code comes from a database or API), import the full variant map. The Flag component uses this approach:

// Loads all flags in the variant — use when the code isn't known at build time
import { circleFlags } from '@blade-flags/core/flags/circle'
import { resolveFlag } from '@blade-flags/core'

const countrySvg = resolveFlag(circleFlags, 'us')              // country flag
const languageSvg = resolveFlag(circleFlags, 'ar-sa', 'language') // language flag
Import style When to use Bundle impact
import { countryUs } from '.../circle' You know the flags at build time Only the flags you import
import { circleFlags } from '.../circle' Code is dynamic (from data/API) All flags in the variant

Flag Variants

Import only the variant you need:

import { defaultFlags } from '@blade-flags/core/flags/default'  // 264 country + 281 language
import { circleFlags } from '@blade-flags/core/flags/circle'    // 405 country + 275 language
import { flatFlags } from '@blade-flags/core/flags/flat'        // 270 country + 264 language
Package Description
@blade-flags/core SVG strings as JS modules + resolveFlag() helper
@blade-flags/vue <Flag> component for Vue 3 (peer dep: vue ^3.3)
@blade-flags/react <Flag> component for React 18+ (peer dep: react ^18 | ^19)

The AutoFlag convenience component accepts a variant string prop but bundles all variants:

<script setup>
import { AutoFlag } from '@blade-flags/vue'
</script>

<template>
  <AutoFlag code="us" variant="circle" />
</template>

Disclaimer

This package aims for broad compatibility by mirroring upstream flag collections. Inclusion of any flag does not imply endorsement. The author of this package stands with Palestine (the Palestine flag is featured in the project cover). If you want to exclude specific flags, you can do so in your application/UI, or exclude them during the build via bin/build.sh.

Contributing

Please see CONTRIBUTING for details.

License

Blade Flags is open-sourced software licensed under the MIT license.

outhebox/blade-flags 适用场景与选型建议

outhebox/blade-flags 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 872.28k 次下载、GitHub Stars 达 306, 最近一次更新时间为 2022 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「flags」 「laravel」 「blade」 「country flags」 「language flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 outhebox/blade-flags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 outhebox/blade-flags 我们能提供哪些服务?
定制开发 / 二次开发

基于 outhebox/blade-flags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 872.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 306
  • 点击次数: 16
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 306
  • Watchers: 3
  • Forks: 31
  • 开发语言: TypeScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-21