SHARE
TWEET

Untitled

a guest Apr 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func WriteLanguageFiles(csvFilePath string) *u.ErrorResponse {
  2.     csvFile, err := os.Open(csvFilePath)
  3.     if err != nil {
  4.         u.ErrorLogger.Println("Cannot open file:"+csvFilePath, err)
  5.         return u.ReturnErrorResponse(err, "Cannot open file:"+csvFilePath)
  6.  
  7.     }
  8.  
  9.     csvFileContent, err := csv.NewReader(csvFile).ReadAll()
  10.     for i, lang := range csvFileContent[0][1:] {
  11.         absPath, err := filepath.Abs(outputPath + lang + ".json")
  12.         if err != nil {
  13.             u.ErrorLogger.Println("Cannot get path specified: \""+lang+".json\"", err)
  14.             return u.ReturnErrorResponse(err, "Cannot get path specified: \""+lang+".json\"")
  15.         }
  16.  
  17.         file, err := os.OpenFile(absPath, os.O_CREATE|os.O_WRONLY, 0644)
  18.         if err != nil {
  19.             u.ErrorLogger.Println("Cannot open file: \""+lang+".json\"", err)
  20.             return u.ReturnErrorResponse(err, "Cannot open file: \""+lang+".json\"")
  21.         }
  22.         file.Truncate(0)
  23.         mapLn := map[string]string{}
  24.         u.GeneralLogger.Println("Language:", lang, i)
  25.         for j, row := range csvFileContent[1:] {
  26.             // fmt.Println(csvFileContent[j+1][0], row[i+1])
  27.             mapLn[csvFileContent[j+1][0]] = row[i+1]
  28.         }
  29.         encodedJSON, _ := json.Marshal(mapLn)
  30.         // u.GeneralLogger.Println(string(encodedJSON))
  31.         file.Write(encodedJSON)
  32.         file.Close()
  33.     }
  34.     return u.ReturnErrorResponse(nil, "")
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top