diff options
author | Dessalines <dessalines@users.noreply.github.com> | 2019-08-09 17:14:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-09 17:14:43 -0700 |
commit | 536c3f491546b4546f43a46e7a1a699ca9ac2934 (patch) | |
tree | f080c86e51b9660560ac493cb7f6d9676ea12fbe /ui/src/components/search.tsx | |
parent | 5a1e8aa645c9f0898e765b45c2f362308292db26 (diff) |
Adding support for internationalization / i18n (#189)
* Still not working
* Starting to work on internationalization
* Main done.
* i18n translations first pass.
* Localization testing mostly done.
* Second front end pass.
* Added a few more translations.
* Adding back end translations.
Diffstat (limited to 'ui/src/components/search.tsx')
-rw-r--r-- | ui/src/components/search.tsx | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index ec657bb1..01122fd4 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -6,6 +6,8 @@ import { WebSocketService } from '../services'; import { msgOp, fetchLimit } from '../utils'; import { PostListing } from './post-listing'; import { CommentNodes } from './comment-nodes'; +import { i18n } from '../i18next'; +import { T } from 'inferno-i18next'; interface SearchState { q: string, @@ -52,7 +54,7 @@ export class Search extends Component<any, SearchState> { } componentDidMount() { - document.title = `Search - ${WebSocketService.Instance.site.name}`; + document.title = `${i18n.t('search')} - ${WebSocketService.Instance.site.name}`; } render() { @@ -60,7 +62,7 @@ export class Search extends Component<any, SearchState> { <div class="container"> <div class="row"> <div class="col-12"> - <h5>Search</h5> + <h5><T i18nKey="search">#</T></h5> {this.selects()} {this.searchForm()} {this.state.type_ == SearchType.Both && @@ -83,11 +85,11 @@ export class Search extends Component<any, SearchState> { searchForm() { return ( <form class="form-inline" onSubmit={linkEvent(this, this.handleSearchSubmit)}> - <input type="text" class="form-control mr-2" value={this.state.q} placeholder="Search..." onInput={linkEvent(this, this.handleQChange)} required minLength={3} /> + <input type="text" class="form-control mr-2" value={this.state.q} placeholder={`${i18n.t('search')}...`} onInput={linkEvent(this, this.handleQChange)} required minLength={3} /> <button type="submit" class="btn btn-secondary mr-2"> {this.state.loading ? <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : - <span>Search</span> + <span><T i18nKey="search">#</T></span> } </button> </form> @@ -98,19 +100,19 @@ export class Search extends Component<any, SearchState> { return ( <div className="mb-2"> <select value={this.state.type_} onChange={linkEvent(this, this.handleTypeChange)} class="custom-select custom-select-sm w-auto"> - <option disabled>Type</option> - <option value={SearchType.Both}>Both</option> - <option value={SearchType.Comments}>Comments</option> - <option value={SearchType.Posts}>Posts</option> + <option disabled><T i18nKey="type">#</T></option> + <option value={SearchType.Both}><T i18nKey="both">#</T></option> + <option value={SearchType.Comments}><T i18nKey="comments">#</T></option> + <option value={SearchType.Posts}><T i18nKey="posts">#</T></option> </select> <select value={this.state.sort} onChange={linkEvent(this, this.handleSortChange)} class="custom-select custom-select-sm w-auto ml-2"> - <option disabled>Sort Type</option> - <option value={SortType.New}>New</option> - <option value={SortType.TopDay}>Top Day</option> - <option value={SortType.TopWeek}>Week</option> - <option value={SortType.TopMonth}>Month</option> - <option value={SortType.TopYear}>Year</option> - <option value={SortType.TopAll}>All</option> + <option disabled><T i18nKey="sort_type">#</T></option> + <option value={SortType.New}><T i18nKey="new">#</T></option> + <option value={SortType.TopDay}><T i18nKey="top_day">#</T></option> + <option value={SortType.TopWeek}><T i18nKey="week">#</T></option> + <option value={SortType.TopMonth}><T i18nKey="month">#</T></option> + <option value={SortType.TopYear}><T i18nKey="year">#</T></option> + <option value={SortType.TopAll}><T i18nKey="all">#</T></option> </select> </div> ) @@ -171,9 +173,9 @@ export class Search extends Component<any, SearchState> { return ( <div class="mt-2"> {this.state.page > 1 && - <button class="btn btn-sm btn-secondary mr-1" onClick={linkEvent(this, this.prevPage)}>Prev</button> + <button class="btn btn-sm btn-secondary mr-1" onClick={linkEvent(this, this.prevPage)}><T i18nKey="prev">#</T></button> } - <button class="btn btn-sm btn-secondary" onClick={linkEvent(this, this.nextPage)}>Next</button> + <button class="btn btn-sm btn-secondary" onClick={linkEvent(this, this.nextPage)}><T i18nKey="next">#</T></button> </div> ); } @@ -183,7 +185,7 @@ export class Search extends Component<any, SearchState> { return ( <div> {res && res.op && res.posts.length == 0 && res.comments.length == 0 && - <span>No Results</span> + <span><T i18nKey="no_results">#</T></span> } </div> ) @@ -244,13 +246,13 @@ export class Search extends Component<any, SearchState> { console.log(msg); let op: UserOperation = msgOp(msg); if (msg.error) { - alert(msg.error); + alert(i18n.t(msg.error)); return; } else if (op == UserOperation.Search) { let res: SearchResponse = msg; this.state.searchResponse = res; this.state.loading = false; - document.title = `Search - ${this.state.q} - ${WebSocketService.Instance.site.name}`; + document.title = `${i18n.t('search')} - ${this.state.q} - ${WebSocketService.Instance.site.name}`; window.scrollTo(0,0); this.setState(this.state); } |