2.1.5 • Published 4 days ago

mui-language-picker v2.1.5

Weekly downloads
199
License
MIT
Repository
github
Last release
4 days ago

mui-language-picker

Material UI react language picker

Installation

Complete information for material-ui.

npm install mui-language-picker --save

Demo

Demo of mui-language-picker / Same demo as a video / Try it yourself

see also: demo repo

Usage

TypeScript React 18 code

import {
  LanguagePicker,
  ILanguagePickerStrings,
  languagePickerStrings_en,
  LangTag,
} from "mui-language-picker";

const MyComponent = (props: any) => {
  const [bcp47, setBcp47] = React.useState("und");
  const [lgName, setLgName] = React.useState("");
  const [fontName, setFontName] = React.useState("");
  const [rtl, setRtl] = React.useState(false);
  const [tag, setTag] = React.useState<LangTag>();

  const displayName = (name: string, tag?: LangTag) => {
    return tag?.localname ? `${tag?.localname} / ${name}` : tag?.name || name;
  };

  return (
    <LanguagePicker
      value={bcp47}
      setCode={setBcp47}
      name={lgName}
      setName={setLgName}
      font={fontName}
      setFont={setFontName}
      setDir={setRtl}
      displayName={displayName}
      setInfo={setTag}
      t={languagePickerStrings_en}
    />
  );
};
Output should be a Language Picker when entered opens a dialog

Parameter definitions

ParameterTypeMeaning
valuestringBCP 47 language code
setCode*(value: string) => voidcallback to change BCP 47 value
namestringlanguage name
setName*(name: string) => voidcallback to change language name
fontstringfont family name
setFont*(font: string) => voidcallback to change font family name
setDir*(rtl: boolean) => voidcallback to change script direction
displayName*DisplayNamefunction to control display of name
setInfo*(tag: LangTag) => voidcallback to receive tag information
disabled*booleantrue if control disabled
offline*booleantrue if picker in offline setting
required*booleantrue if language required (show *)
tILanguagePickerStringslocalization strings (see below)

* parameters marked with an asterisk are optional

Helper functions

import {
  getLangTag,
  getRtl,
  getFamily
} from "mui-language-picker";

console.log(getLangTag(tag)) // Return langTag object (see below)
console.log(getRtl(tag)) // returns true if rtl script
console.log(getFamily(familyId)) // Returns fontFamily object (see below)

The fontName returned by the Language Picker is the familyId. Refer to fonts.languagetechnology.org for more information.

Localization Strings

export const languagePickerStrings_en = {
  font: 'Font',
  script: 'Script',
  language: 'Language',
  selectLanguage: 'Choose Language Details',
  findALanguage: 'Find a language by name, code, or country',
  codeExplained: 'Code Explained',
  subtags: 'Subtags',
  details: 'Details',
  languageOf: 'A Language of $1$2.',
  inScript: ' in the $1 script',
  select: 'Save',
  cancel: 'Cancel',
  phonetic: 'Phonetic',
  changeName: 'Change Name',
  nameInstruction:
    'If you would like to change the language name enter the new name here.',
  newName: 'New Language Name',
  change: 'Change',
  noFonts: 'No recommended fonts',
} as ILanguagePickerStrings;

Information returned by setInfo

export interface LangTag {
  full: string;
  iana?: string[];
  iso639_3?: string;
  localname?: string;
  localnames?: string[];
  name: string;
  names?: string[];
  nophonvars?: boolean;
  region?: string;
  regionname?: string;
  regions?: string[];
  script: string;
  sldr: boolean;
  suppress?: boolean;
  tag: string;
  tags?: string[];
  variants?: string[];
  defaultFont?: string;
  fonts?: string[];
  windows?: string;
}

Information returned by getFamily

export interface IFamily {
  defaults?: {
    ttf: string;
    woff?: string;
    woff2?: string;
  };
  distributable: boolean;
  fallback?: string;
  family: string;
  familyid: string;
  files?: {
    [fileid: string]: {
      axes: {
        ital?: number;
        wght: number;
      };
      flourl?: string;
      packagepath: string;
      url?: string;
      zippath?: string;
    };
  };
  license?: 'OFL' | 'GPL3' | 'GPL' | 'Freeware' | 'proprietary' | 'shareware';
  packageurl?: string;
  siteurl?: string;
  source?:
    | 'SIL'
    | 'Google'
    | 'Microsoft'
    | 'NLCI'
    | 'STAR'
    | 'Evertype'
    | 'Lao Script';
  status?: 'current' | 'archived' | 'deprecated';
  version?: string;
  ziproot?: string;
}

Change control background

If the theme involves using a dark background, the control background can be changed with css. See also material-ui documentation.

#LangBcp47 .MuiFilledInput-root {
  background-color: rgba(255, 255, 255, 0.9);
}

Build

npm install
npm run build

Test

npm run clean
npm run index
npm test

Testing Individual Suites

Here is an example for Language Picker tests:

npm test -- --watch LanguagePicker
2.1.5

4 days ago

2.1.4

5 days ago

2.1.3

5 days ago

2.1.2

9 days ago

2.1.1

10 days ago

2.1.0

11 days ago

2.0.0

22 days ago

1.3.0

1 month ago

1.2.8

9 months ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago