Best Gauge code snippet using lang.contains
i18n.go
Source:i18n.go
...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 {...
my_language.go
Source:my_language.go
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}...
gotemplates_test.go
Source:gotemplates_test.go
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}...
contains
Using AI Code Generation
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
contains
Using AI Code Generation
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
contains
Using AI Code Generation
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}
contains
Using AI Code Generation
1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15 fmt.Println(strings.EqualFold
contains
Using AI Code Generation
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() {
contains
Using AI Code Generation
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}
contains
Using AI Code Generation
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}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!