How to use contains method of lang Package

Best Gauge code snippet using lang.contains

i18n.go

Source:i18n.go Github

copy

Full Screen

...72 defer tx.Rollback()73 var query db.Query74 m := make(map[string]map[string]string)75 if keyContains != "" {76 keyContains = containsCaseInsensitiveReg(keyContains)77 query = tx.Select(q.Re("Code", keyContains))78 } else if keyContains != "" && valueContains != "" {79 keyContains = containsCaseInsensitiveReg(keyContains)80 valueContains = containsCaseInsensitiveReg(valueContains)81 query = tx.Select(q.Or(q.Re("Code", keyContains), q.Re("Text", valueContains)))82 } else if valueContains != "" {83 valueContains = regexp.QuoteMeta(valueContains)84 query = tx.Select(q.Re("Text", valueContains))85 } else {86 query = tx.Select()87 }88 err = query.89 Limit(sQuery.limit).90 Skip(sQuery.index).91 OrderBy("Code", "Text").92 Each(new(i18nInternal), func(record interface{}) error {93 item := record.(*i18nInternal)94 if m[item.Code] == nil {...

Full Screen

Full Screen

my_language.go

Source:my_language.go Github

copy

Full Screen

1package language2import (3 "github.com/allanpk716/ChineseSubFinder/internal/types/language"4 "strings"5)6// LangConverter4Sub_Supplier 语言转换器,给字幕的提供者实例解析使用(xunlei、zimuku等)7// 支持的字符串语言见 internal/types/language/my_language.go8func LangConverter4Sub_Supplier(subLang string) language.MyLanguage {9 /*10 xunlei:未知语言、简体&英语、繁体&英语、简体、繁体、英语11 */12 if strings.Contains(subLang, language.MatchLangDouble) {13 // 双语 - 简英14 return language.ChineseSimpleEnglish15 } else if strings.Contains(subLang, language.MatchLangChs) {16 // 优先简体17 if strings.Contains(subLang, language.MatchLangEn) {18 // 简英19 return language.ChineseSimpleEnglish20 } else if strings.Contains(subLang, language.MatchLangJp) {21 // 简日22 return language.ChineseSimpleJapanese23 } else if strings.Contains(subLang, language.MatchLangKr) {24 // 简韩25 return language.ChineseSimpleKorean26 }27 // 默认简体中文28 return language.ChineseSimple29 } else if strings.Contains(subLang, language.MatchLangCht) {30 // 然后是繁体31 if strings.Contains(subLang, language.MatchLangEn) {32 // 繁英33 return language.ChineseTraditionalEnglish34 } else if strings.Contains(subLang, language.MatchLangJp) {35 // 繁日36 return language.ChineseTraditionalJapanese37 } else if strings.Contains(subLang, language.MatchLangKr) {38 // 繁韩39 return language.ChineseTraditionalKorean40 }41 // 默认繁体中文42 return language.ChineseTraditional43 } else if strings.Contains(subLang, language.MatchLangEn) {44 // 英文45 return language.English46 } else if strings.Contains(subLang, language.MatchLangJp) {47 // 日文48 return language.Japanese49 } else if strings.Contains(subLang, language.MatchLangKr) {50 // 韩文51 return language.Korean52 } else {53 // 都没有,则标记未知54 return language.Unknown55 }56}57// HasChineseLang 是否包含中文58func HasChineseLang(lan language.MyLanguage) bool {59 switch lan {60 case language.ChineseSimple,61 language.ChineseTraditional,62 language.ChineseSimpleEnglish,63 language.ChineseTraditionalEnglish,64 language.ChineseSimpleJapanese,65 language.ChineseTraditionalJapanese,66 language.ChineseSimpleKorean,67 language.ChineseTraditionalKorean:68 return true69 default:70 return false71 }72}73// IsBilingualSubtitle 是否是双语字幕74func IsBilingualSubtitle(lan language.MyLanguage) bool {75 switch lan {76 case language.ChineseSimpleEnglish,77 language.ChineseTraditionalEnglish,78 language.ChineseSimpleJapanese,79 language.ChineseTraditionalJapanese,80 language.ChineseSimpleKorean,81 language.ChineseTraditionalKorean:82 return true83 default:84 return false85 }86}87// Lang2ChineseString 将 types.MyLanguage 转换为中文描述:简、繁、简英88// 支持的字符串语言见 internal/types/language/my_language.go89func Lang2ChineseString(lan language.MyLanguage) string {90 switch lan {91 case language.Unknown:92 // 未知语言93 return language.MathLangChnUnknown94 case language.ChineseSimple:95 // 简体中文96 return language.MatchLangChs97 case language.ChineseTraditional:98 // 繁体中文99 return language.MatchLangCht100 case language.ChineseSimpleEnglish:101 // 简英双语字幕102 return language.MatchLangChsEn103 case language.ChineseTraditionalEnglish:104 // 繁英双语字幕105 return language.MatchLangChtEn106 case language.English:107 // 英文108 return language.MatchLangEn109 case language.Japanese:110 // 日语111 return language.MatchLangJp112 case language.ChineseSimpleJapanese:113 // 简日双语字幕114 return language.MatchLangChsJp115 case language.ChineseTraditionalJapanese:116 // 繁日双语字幕117 return language.MatchLangChtJp118 case language.Korean:119 // 韩语120 return language.MatchLangKr121 case language.ChineseSimpleKorean:122 // 简韩双语字幕123 return language.MatchLangChsKr124 case language.ChineseTraditionalKorean:125 // 繁韩双语字幕126 return language.MatchLangChtKr127 default:128 return language.MathLangChnUnknown129 }130}131// ChineseString2Lang 将 中文描述:简、繁、简英 转换为 types.MyLanguage132// 支持的字符串语言见 internal/types/language/my_language.go133func ChineseString2Lang(chineseStr string) language.MyLanguage {134 switch chineseStr {135 case language.MathLangChnUnknown:136 // 未知语言137 return language.Unknown138 case language.MatchLangChs:139 // 简体中文140 return language.ChineseSimple141 case language.MatchLangCht:142 // 繁体中文143 return language.ChineseTraditional144 case language.MatchLangChsEn:145 // 简英双语字幕146 return language.ChineseSimpleEnglish147 case language.MatchLangChtEn:148 // 繁英双语字幕149 return language.ChineseTraditionalEnglish150 case language.MatchLangEn:151 // 英文152 return language.English153 case language.MatchLangJp:154 // 日语155 return language.Japanese156 case language.MatchLangChsJp:157 // 简日双语字幕158 return language.ChineseSimpleJapanese159 case language.MatchLangChtJp:160 // 繁日双语字幕161 return language.ChineseTraditionalJapanese162 case language.MatchLangKr:163 // 韩语164 return language.Korean165 case language.MatchLangChsKr:166 // 简韩双语字幕167 return language.ChineseSimpleKorean168 case language.MatchLangChtKr:169 // 繁韩双语字幕170 return language.ChineseTraditionalKorean171 default:172 return language.Unknown173 }174}...

Full Screen

Full Screen

gotemplates_test.go

Source:gotemplates_test.go Github

copy

Full Screen

1package gotemplates2import (3 "errors"4 "net/http"5 "strings"6 "testing"7 "time"8 "github.com/dchest/uniuri"9 "github.com/stretchr/testify/require"10 "golang.org/x/text/language"11)12var (13 htmlTemplates = map[string]map[string]string{14 "en": {15 "subject": "hello",16 "text": `text: lang=en {{ .Email }} {{ .URL }} {{ .Expiration.Format "Jan 02, 2006"}}`,17 "html": `<div>lang=en {{ .Email }} {{ .URL }} {{ .Expiration.Format "Jan 02, 2006"}}</div>`,18 },19 "fr": {20 "subject": "salut",21 "text": `text: lang=fr {{ .Email }} {{ .URL }} {{ .Expiration.Format "Jan 02, 2006"}}`,22 "html": `<div>lang=fr {{ .Email }} {{ .URL }} {{ .Expiration.Format "Jan 02, 2006"}}</div>`,23 },24 }25 expiration = time.Now()26 email = "my.email@example.com"27 url = uniuri.New()28)29func createTemplates(t *testing.T) *GoTemplates {30 tmpl := NewTemplates()31 for lang, group := range htmlTemplates {32 tmpl.Add(lang, group["subject"], group["text"], group["html"])33 }34 err := tmpl.SetDefaultLanguage("en")35 require.Nil(t, err)36 require.Equal(t, language.English, tmpl.tags[0])37 return tmpl38}39func TestCorrectTags(t *testing.T) {40 tmpl := createTemplates(t)41 require.Equal(t, tmpl.tags[0], language.English)42 require.Equal(t, tmpl.tags[1], language.French)43}44func TestSetDefaultLanguage(t *testing.T) {45 tmpl := createTemplates(t)46 err := tmpl.SetDefaultLanguage("fr")47 require.Nil(t, err)48 require.Equal(t, tmpl.tags[0], language.French)49 require.Equal(t, tmpl.tags[1], language.English)50}51func TestGenerate(t *testing.T) {52 tmpl := createTemplates(t)53 res, err := tmpl.Generate(email, url, expiration)54 require.Nil(t, err)55 require.Nil(t, validateTemplate("en", true, res.HTML))56 require.Nil(t, validateTemplate("en", false, res.TXT))57}58func TestGenerateForLang(t *testing.T) {59 tmpl := createTemplates(t)60 for _, al := range []struct {61 lang string62 expected string63 }{64 {"en", "en"},65 {"en-US", "en"},66 {"fr", "fr"},67 {"zh", "en"},68 {"invalid!", "en"},69 } {70 res, err := tmpl.GenerateForLang(al.lang, email, url, expiration)71 require.Nil(t, err)72 require.Nil(t, validateTemplate(al.expected, true, res.HTML), al.lang)73 require.Nil(t, validateTemplate(al.expected, false, res.TXT), al.lang)74 }75}76func TestGenerateForRequest(t *testing.T) {77 tmpl := createTemplates(t)78 for _, al := range []struct {79 header string80 expected string81 }{82 {"nn;q=0.3, en-us;q=0.8, en,", "en"},83 {"en-US,en;q=0.9,fr;q=0.8", "en"},84 {"fr-FR,en;q=0.8,fr;q=0.9", "fr"},85 {"gsw, en;q=0.7, en-US;q=0.8", "en"},86 {"gsw, nl, da", "en"},87 {"zh-ZH", "en"},88 {"invalid", "en"},89 } {90 r, _ := http.NewRequest("GET", "example.com", strings.NewReader("Hello"))91 r.Header.Set("Accept-Language", al.header)92 res, err := tmpl.GenerateForRequest(r, email, url, expiration)93 require.Nil(t, err, al.header)94 require.Nil(t, validateTemplate(al.expected, true, res.HTML), al.header, al.expected)95 require.Nil(t, validateTemplate(al.expected, false, res.TXT), al.header, al.expected)96 }97}98func validateTemplate(lang string, html bool, res []byte) error {99 if res == nil || len(res) == 0 {100 return errors.New("empty template")101 }102 str := string(res)103 if !strings.Contains(str, "lang="+lang) {104 return errors.New("invalid language " + string(res))105 }106 if html {107 if !strings.Contains(str, "<div>") {108 return errors.New("not html")109 }110 } else {111 if !strings.Contains(str, "text") {112 return errors.New("not text")113 }114 }115 if !strings.Contains(str, email) {116 return errors.New("email not present")117 }118 if !strings.Contains(str, url) {119 return errors.New("url not present")120 }121 if !strings.Contains(str, expiration.Format("Jan 02, 2006")) {122 return errors.New("expiration not present")123 }124 return nil125}...

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15 fmt.Println(strings.EqualFold("Go

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "strings"3func main() {4 fmt.Println(strings.Contains("test", "es"))5}6import "fmt"7import "strings"8func main() {9 fmt.Println(strings.Contains("test", "es"))10 fmt.Println(strings.Contains("test", "es"))11 fmt.Println(strings.Contains("test", "es"))12}13import "fmt"14import "strings"15func main() {16 fmt.Println(st

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(strings.Contains(str, "Hello"))4 fmt.Println(strings.Contains(str, "World"))5 fmt.Println(strings.Contains(str, "Mars"))6}

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15 fmt.Println(strings.EqualFold

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(strings.Contains("test", "es"))4}5import (6func main() {7 fmt.Println(strings.Contains("test", "es"))8 fmt.Println(strings.Contains("test", "es"))9 fmt.Println(strings.Contains("test", "es"))10}11import (12func main() {

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Contains: ", strings.Contains("test", "es"))4}5strings.ContainsAny(str, chars)6import "fmt"7func main() {8 fmt.Println("ContainsAny: ", strings.ContainsAny("test", "te"))9}10strings.ContainsRune(str, char)11import "fmt"12func main() {13 fmt.Println("ContainsRune: ", strings.ContainsRune("test", 101))14}

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1{2 public static void main(String[] args) {3 String str = "Hello World";4 String str1 = "Hello";5 String str2 = "World";6 boolean b = str.contains(str1);7 System.out.println(b);8 boolean b1 = str.contains(str2);9 System.out.println(b1);10 }11}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful